oebb_py/workers/conn.py
2017-09-21 23:04:32 +02:00

23 lines
888 B
Python

from bs4 import BeautifulSoup
import requests
import datetime
import workers.val
def connRequest(frm, to, count = 3, time = datetime.datetime.now(), mode = False):
outdate = datetime.datetime.strftime(time,"%d.%m.%Y")
outtime = datetime.datetime.strftime(time,"%H:%M")
url = "http://fahrplan.oebb.at/bin/query.exe/dn?start=1&S=%s&Z=%s&REQ0JourneyDate=%s&time=%s&REQ0HafasNumCons0=%s%s" % (frm.extid if frm.extid else frm.name, to.extid if to.extid else to.name, outdate, outtime, count, "&timesel=arrive" if mode else "")
source = requests.get(url).text
if "GO_conViewMode=outward" not in source:
raise ValueError("No connection found.")
return source
def getStation(name):
return list(workers.val.validateName(name))[0]
def worker(frm, to, count = 3, time = datetime.datetime.now(), mode = False):
source = connRequest(frm, to, count, time, mode)
conns = dissem(source)