commit dcc774b92ff5207f418b01a152fa6fece2bc4a48 Author: Phyks (Lucas Verney) Date: Fri Dec 14 10:51:43 2018 +0100 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7911f70 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +lastrun.json diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..1354996 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2018 Phyks (Lucas Verney) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..62816e5 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +Montrouge +========= + +These are just some helper scripts to fetch documents and notify about updates +from the official Website of the Montrouge City (http://ville-montrouge.fr/). diff --git a/montrouge.py b/montrouge.py new file mode 100644 index 0000000..6360c95 --- /dev/null +++ b/montrouge.py @@ -0,0 +1,61 @@ +# 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=(',', ': ')) +try: + with open('lastrun.json', 'r') as fh: + lastrun = fh.read() + # If something changed, print the fetched data and exit 1 to ensure chronic + # sends an email. + if lastrun != dump: + print(dump) + sys.exit(1) +except IOError: + pass + +with open('lastrun.json', 'w') as fh: + fh.write(dump) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e72eca2 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +bs4 +lxml +requests