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

montrouge.py 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. try:
  45. with open('lastrun.json', 'r') as fh:
  46. lastrun = fh.read()
  47. # If something changed, print the fetched data and exit 1 to ensure chronic
  48. # sends an email.
  49. if lastrun != dump:
  50. print(dump)
  51. sys.exit(1)
  52. except IOError:
  53. pass
  54. with open('lastrun.json', 'w') as fh:
  55. fh.write(dump)