From 9f7bf662c213d237144c3d093577bb3400278a13 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Thu, 14 Mar 2019 10:46:39 +0100 Subject: [PATCH] Fixes for changes in OEBB website --- workers/conn.py | 22 ++++++++++++---------- workers/val.py | 5 +++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/workers/conn.py b/workers/conn.py index 28fc7d7..bd8b012 100644 --- a/workers/conn.py +++ b/workers/conn.py @@ -21,8 +21,8 @@ def getService(sid, lines, q, eq = None): depdate = dep.find("td", { "class": "date" }).string.strip() or None deptime = dep.find("td", { "class": "timeValue" }).find("span").string.split()[1].strip() - depprog = dep.find("span", { "class": "prognosis" }).find("span").string.strip() if dep.find("span", { "class": "prognosis" }).find("span") else None - depplat = dep.find("td", { "class": "platform" }).find("span").string.strip() if dep.find("td", { "class": "platform" }).find("span") else None + depprog = dep.find("span", { "class": "prognosis" }).find("span").string.strip() if dep.find("span", { "class": "prognosis" }) and dep.find("span", { "class": "prognosis" }).find("span") else None + depplat = dep.find("td", { "class": "platform" }).find("span").string.strip() if dep.find("td", { "class": "platform" }) and dep.find("td", { "class": "platform" }).find("span") else None walk = dep.find("img", { "class": "product" }).get("src") == "/img/vs_oebb/fuss_pic.gif" name = dep.find("img", { "class": "product" }).get("alt") if not walk else "Walk" @@ -41,15 +41,17 @@ def getService(sid, lines, q, eq = None): dest = None if not (walk or depdate): - purl = dep.find("td", { "class": "product" }).find("a").get("href") - psource = HTTPClient().get(purl).text + try: + purl = dep.find("td", { "class": "product" }).find("a").get("href") + psource = HTTPClient().get(purl).text + zuppa = BeautifulSoup(psource, "html5lib") + depdate = zuppa.findAll("div", { "class": "block" })[1].text.strip() + arrdate = depdate + dest = list(workers.val.validateName(zuppa.findAll("div", { "class": "block" })[2].text.split(":")[1].strip()))[0] + except: + pass - zuppa = BeautifulSoup(psource, "html5lib") - depdate = zuppa.findAll("div", { "class": "block" })[1].text.strip() - arrdate = depdate - dest = list(workers.val.validateName(zuppa.findAll("div", { "class": "block" })[2].text.split(":")[1].strip()))[0] - - elif not depdate: + if not walk and not depdate: depdate = "01.01.2000" arrdate = depdate diff --git a/workers/val.py b/workers/val.py index 520b132..f0112c9 100644 --- a/workers/val.py +++ b/workers/val.py @@ -3,11 +3,12 @@ import urllib.parse from classes import * def getValidator(name): - return HTTPClient().get("http://www.oebb.at/__ressources/system/stationsHafas.jsp?q=%s" % urllib.parse.quote(name)).text + data = HTTPClient().get("http://scotty.oebb.at/bin/ajax-getstop.exe/dn?REQ0JourneyStopsS0A=255&REQ0JourneyStopsB=12&S=%s?&js=true&" % urllib.parse.quote(name)).text + return "=".join(data.split("=")[1:]).split(";")[0] def validateName(name): stations = json.loads(getValidator(name)) - for station in stations: + for station in stations["suggestions"]: name = station["value"] sttype = station["type"] try: