|
@@ -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)
|