Check updates about "Conseils Municipaux" and "Comités de Quartier" on Montrouge website.

montrouge.py 1.9KB

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