You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.9 KiB
60 lines
1.9 KiB
# coding: utf-8 |
|
import json |
|
import sys |
|
|
|
import bs4 as BeautifulSoup |
|
import requests |
|
|
|
data = { |
|
"comitesDeQuartier": { |
|
"Ferry-Buffalo": [], |
|
"Jean Jaurès": [], |
|
"Plein Sud": [], |
|
"Portes de Montrouge": [], |
|
"Montrouge Est": [], |
|
"Vieux Montrouge": [], |
|
}, |
|
"conseilsMunicipaux": [] |
|
} |
|
|
|
# Get Conseils Municipaux |
|
r = requests.get( |
|
"https://www.ville-montrouge.fr/621-les-seances-publiques-et-deliberations.htm" |
|
) |
|
soup = BeautifulSoup.BeautifulSoup(r.text, features='lxml') |
|
main= soup.find('main', attrs={"id": "corps"}) |
|
table = main.find('table') |
|
a = table.findAll('a') |
|
data["conseilsMunicipaux"] = ["https://www.ville-montrouge.fr" + x.attrs['href'] for x in a] |
|
|
|
# Handle Comités de Quartier |
|
URLS = { |
|
"Ferry-Buffalo": "https://www.ville-montrouge.fr/688-comite-ferry-buffalo.htm", |
|
"Jean Jaurès": "https://www.ville-montrouge.fr/689-comite-jean-jaures.htm", |
|
"Plein Sud": "https://www.ville-montrouge.fr/692-comite-plein-sud.htm", |
|
"Portes de Montrouge": "https://www.ville-montrouge.fr/690-comite-portes-de-montrouge.htm", |
|
"Montrouge Est": "https://www.ville-montrouge.fr/691-comite-montrouge-est.htm", |
|
"Vieux Montrouge": "https://www.ville-montrouge.fr/693-comite-vieux-montrouge.htm", |
|
} |
|
for (k, url) in URLS.items(): |
|
r = requests.get(url) |
|
soup = BeautifulSoup.BeautifulSoup(r.text, features='lxml') |
|
div = soup.find('div', attrs={"class": "enSavoirPlusParagraphe PRS_ENCADRE txt"}) |
|
if div: |
|
a = div.findAll('a') |
|
data["comitesDeQuartier"][k] = ["https://www.ville-montrouge.fr" + x.attrs['href'] for x in a] |
|
|
|
dump = json.dumps(data, sort_keys=True, |
|
indent=4, separators=(',', ': ')) |
|
|
|
with open('lastrun.json', 'r') as fh: |
|
lastrun = fh.read() |
|
|
|
with open('lastrun.json', 'w') as fh: |
|
fh.write(dump) |
|
|
|
# If something changed, print the fetched data and exit 1 to ensure chronic |
|
# sends an email. |
|
if lastrun != dump: |
|
print(dump) |
|
sys.exit(1)
|
|
|