summaryrefslogtreecommitdiff
path: root/jobs/prix_carburant.py
diff options
context:
space:
mode:
authorYves Fischer <yvesf-git@xapek.org>2018-12-25 20:30:09 +0100
committerYves Fischer <yvesf-git@xapek.org>2018-12-25 20:30:09 +0100
commit0b24f896bde7cf709df9193ed3a33b69f7640361 (patch)
tree2a4e5293153768bdf278fed3d7924228996ee777 /jobs/prix_carburant.py
parentffddda74331a3a95d9ae48c0a499d8e8e377a1f5 (diff)
downloaddatasources-0b24f896bde7cf709df9193ed3a33b69f7640361.tar.gz
datasources-0b24f896bde7cf709df9193ed3a33b69f7640361.zip
fix prix carburantHEADmaster
Diffstat (limited to 'jobs/prix_carburant.py')
-rwxr-xr-xjobs/prix_carburant.py16
1 files changed, 9 insertions, 7 deletions
diff --git a/jobs/prix_carburant.py b/jobs/prix_carburant.py
index 0f3eb86..5855d4d 100755
--- a/jobs/prix_carburant.py
+++ b/jobs/prix_carburant.py
@@ -72,18 +72,17 @@ class Parser(HTMLParser):
self._prix.station_name += data.strip() + ". "
-URL = "http://www.prix-carburants.gouv.fr/map/recupererInfosPdv/"
+URL = "https://www.prix-carburants.gouv.fr/map/recupererInfosPdv/"
def _execute(station_id: str):
parser = Parser()
- r = request.Request(URL + station_id)
- r.add_header('Host', 'www.prix-carburants.gouv.fr')
- r.add_header('Referer', 'http://www.prix-carburants.gouv.fr/recherche/map')
- r.add_header('User-Agent', 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0')
+ r = request.Request(URL + station_id, data=b"")
+ r.add_header('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0')
r.add_header('X-Requested-With', 'XMLHttpRequest')
r.add_header('X-Prototype-Version', '1.7')
- r.add_header('Connection', 'close')
+ r.add_header('Connection', 'keep-alive')
+ r.add_header('Content-type', 'application/x-www-form-urlencoded; charset=UTF-8')
with request.urlopen(r) as f:
# with open("info.html", 'rb') as f:
f2 = codecs.getreader('utf-8')(f)
@@ -101,7 +100,10 @@ def _execute(station_id: str):
def execute(*ids) -> typing.Iterable[Station]:
for station_id in ids:
- yield _execute(station_id)
+ try:
+ yield _execute(station_id)
+ except Exception as e:
+ raise Exception("Failed for station {}".format(station_id), e)
if __name__ == "__main__":