Browse Source

Initial commit

Phyks (Lucas Verney) 11 months ago
commit
dcc774b92f
5 changed files with 91 additions and 0 deletions
  1. 1
    0
      .gitignore
  2. 21
    0
      LICENSE.md
  3. 5
    0
      README.md
  4. 61
    0
      montrouge.py
  5. 3
    0
      requirements.txt

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+lastrun.json

+ 21
- 0
LICENSE.md View File

@@ -0,0 +1,21 @@
1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2018 Phyks (Lucas Verney)
4
+
5
+Permission is hereby granted, free of charge, to any person obtaining a copy
6
+of this software and associated documentation files (the "Software"), to deal
7
+in the Software without restriction, including without limitation the rights
8
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+copies of the Software, and to permit persons to whom the Software is
10
+furnished to do so, subject to the following conditions:
11
+
12
+The above copyright notice and this permission notice shall be included in all
13
+copies or substantial portions of the Software.
14
+
15
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+SOFTWARE.

+ 5
- 0
README.md View File

@@ -0,0 +1,5 @@
1
+Montrouge
2
+=========
3
+
4
+These are just some helper scripts to fetch documents and notify about updates
5
+from the official Website of the Montrouge City (http://ville-montrouge.fr/).

+ 61
- 0
montrouge.py View File

@@ -0,0 +1,61 @@
1
+# coding: utf-8
2
+import json
3
+import sys
4
+
5
+import bs4 as BeautifulSoup
6
+import requests
7
+
8
+data = {
9
+    "comitesDeQuartier": {
10
+        "Ferry-Buffalo": [],
11
+        "Jean Jaurès": [],
12
+        "Plein Sud": [],
13
+        "Portes de Montrouge": [],
14
+        "Montrouge Est": [],
15
+        "Vieux Montrouge": [],
16
+    },
17
+    "conseilsMunicipaux": []
18
+}
19
+
20
+# Get Conseils Municipaux
21
+r = requests.get(
22
+    "https://www.ville-montrouge.fr/621-les-seances-publiques-et-deliberations.htm"
23
+)
24
+soup = BeautifulSoup.BeautifulSoup(r.text, features='lxml')
25
+main= soup.find('main', attrs={"id": "corps"})
26
+table = main.find('table')
27
+a = table.findAll('a')
28
+data["conseilsMunicipaux"] = ["https://www.ville-montrouge.fr" + x.attrs['href'] for x in a]
29
+
30
+# Handle Comités de Quartier
31
+URLS = {
32
+    "Ferry-Buffalo": "https://www.ville-montrouge.fr/688-comite-ferry-buffalo.htm",
33
+    "Jean Jaurès": "https://www.ville-montrouge.fr/689-comite-jean-jaures.htm",
34
+    "Plein Sud": "https://www.ville-montrouge.fr/692-comite-plein-sud.htm",
35
+    "Portes de Montrouge": "https://www.ville-montrouge.fr/690-comite-portes-de-montrouge.htm",
36
+    "Montrouge Est": "https://www.ville-montrouge.fr/691-comite-montrouge-est.htm",
37
+    "Vieux Montrouge": "https://www.ville-montrouge.fr/693-comite-vieux-montrouge.htm",
38
+}
39
+for (k, url) in URLS.items():
40
+    r = requests.get(url)
41
+    soup = BeautifulSoup.BeautifulSoup(r.text, features='lxml')
42
+    div = soup.find('div', attrs={"class": "enSavoirPlusParagraphe PRS_ENCADRE txt"})
43
+    if div:
44
+        a = div.findAll('a')
45
+        data["comitesDeQuartier"][k] = ["https://www.ville-montrouge.fr" + x.attrs['href'] for x in a]
46
+
47
+dump = json.dumps(data, sort_keys=True,
48
+                  indent=4, separators=(',', ': '))
49
+try:
50
+    with open('lastrun.json', 'r') as fh:
51
+        lastrun = fh.read()
52
+    # If something changed, print the fetched data and exit 1 to ensure chronic
53
+    # sends an email.
54
+    if lastrun != dump:
55
+        print(dump)
56
+        sys.exit(1)
57
+except IOError:
58
+    pass
59
+
60
+with open('lastrun.json', 'w') as fh:
61
+    fh.write(dump)

+ 3
- 0
requirements.txt View File

@@ -0,0 +1,3 @@
1
+bs4
2
+lxml
3
+requests