Use custom user agent string for outgoing requests
This commit is contained in:
parent
cf7065a567
commit
eb85dd1ec6
|
@ -2,3 +2,6 @@ from classes.connection import Connection
|
||||||
from classes.station import Station
|
from classes.station import Station
|
||||||
from classes.service import Service
|
from classes.service import Service
|
||||||
from classes.train import Train
|
from classes.train import Train
|
||||||
|
from classes.request import Request
|
||||||
|
from classes.response import Response
|
||||||
|
from classes.httpclient import HTTPClient
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import overpy
|
import overpy
|
||||||
import math
|
import math
|
||||||
import workers.val
|
import workers.val
|
||||||
|
from classes.httpclient import HTTPClient
|
||||||
|
|
||||||
def getOSM(lat, lon, distance = 1000):
|
def getOSM(lat, lon, distance = 1000):
|
||||||
query = """
|
query = """[out:json];
|
||||||
(
|
(
|
||||||
node
|
node
|
||||||
(around:%i,%f,%f)
|
(around:%i,%f,%f)
|
||||||
|
@ -20,8 +21,10 @@ def getOSM(lat, lon, distance = 1000):
|
||||||
out;
|
out;
|
||||||
""" % (distance, lat, lon, distance, lat, lon)
|
""" % (distance, lat, lon, distance, lat, lon)
|
||||||
|
|
||||||
api = overpy.Overpass(url="https://overpass.kumi.systems/api/interpreter")
|
endpoint = "https://overpass.kumi.systems/api/interpreter"
|
||||||
res = api.query(query)
|
|
||||||
|
json = HTTPClient().post(endpoint, data={"data": query}).text
|
||||||
|
res = overpy.Overpass().parse_json(json)
|
||||||
|
|
||||||
return res.nodes
|
return res.nodes
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import requests
|
|
||||||
import datetime
|
import datetime
|
||||||
import pytz
|
import pytz
|
||||||
import threading
|
import threading
|
||||||
|
@ -43,7 +42,7 @@ def getService(sid, lines, q, eq = None):
|
||||||
|
|
||||||
if not (walk or depdate):
|
if not (walk or depdate):
|
||||||
purl = dep.find("td", { "class": "product" }).find("a").get("href")
|
purl = dep.find("td", { "class": "product" }).find("a").get("href")
|
||||||
psource = requests.get(purl).text
|
psource = HTTPClient().get(purl).text
|
||||||
|
|
||||||
zuppa = BeautifulSoup(psource, "html5lib")
|
zuppa = BeautifulSoup(psource, "html5lib")
|
||||||
depdate = zuppa.findAll("div", { "class": "block" })[1].text.strip()
|
depdate = zuppa.findAll("div", { "class": "block" })[1].text.strip()
|
||||||
|
@ -69,7 +68,7 @@ def getService(sid, lines, q, eq = None):
|
||||||
|
|
||||||
def getDetails(cid, url, q, via = [], eq = None):
|
def getDetails(cid, url, q, via = [], eq = None):
|
||||||
try:
|
try:
|
||||||
ssource = requests.get(url).text
|
ssource = HTTPClient().get(url).text
|
||||||
suppe = BeautifulSoup(ssource, "html5lib")
|
suppe = BeautifulSoup(ssource, "html5lib")
|
||||||
|
|
||||||
cont = suppe.find("tr", id="trC0-%i" % cid)
|
cont = suppe.find("tr", id="trC0-%i" % cid)
|
||||||
|
@ -138,7 +137,7 @@ def connRequest(frm, to, count = 3, time = datetime.datetime.now(), mode = False
|
||||||
for i in range(len(via)):
|
for i in range(len(via)):
|
||||||
url += "&REQ0JourneyStops%i.0G=%s&REQ0JourneyStops%i.0A=1" % (i + 1, via[i].extid if via[i].extid else via[i].name, i + 1)
|
url += "&REQ0JourneyStops%i.0G=%s&REQ0JourneyStops%i.0A=1" % (i + 1, via[i].extid if via[i].extid else via[i].name, i + 1)
|
||||||
|
|
||||||
source = requests.get(url).text
|
source = HTTPClient().get(url).text
|
||||||
|
|
||||||
if "GO_conViewMode=outward" not in source:
|
if "GO_conViewMode=outward" not in source:
|
||||||
raise ValueError("No connection found.")
|
raise ValueError("No connection found.")
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import requests
|
|
||||||
import json
|
import json
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from classes import *
|
from classes import *
|
||||||
|
|
||||||
def getRadar():
|
def getRadar():
|
||||||
return requests.get("http://zugradar.oebb.at/bin/query.exe/dny?look_minx=-180000000&look_maxx=180000000&look_miny=-90000000&look_maxy=90000000&tpl=trains2json2&look_json=yes&performLocating=1&look_nv=get_zntrainname|no|attr|81|get_rtonly|yes|zugposmode|2|interval|30000|intervalstep|2000|maxnumberoftrains|500000000000|").text
|
return HTTPClient().get("http://zugradar.oebb.at/bin/query.exe/dny?look_minx=-180000000&look_maxx=180000000&look_miny=-90000000&look_maxy=90000000&tpl=trains2json2&look_json=yes&performLocating=1&look_nv=get_zntrainname|no|attr|81|get_rtonly|yes|zugposmode|2|interval|30000|intervalstep|2000|maxnumberoftrains|500000000000|").text
|
||||||
|
|
||||||
def getTrains(names = None):
|
def getTrains(names = None):
|
||||||
trains = json.loads(getRadar())["t"]
|
trains = json.loads(getRadar())["t"]
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import requests
|
|
||||||
import json
|
import json
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from classes import *
|
from classes import *
|
||||||
|
|
||||||
def getValidator(name):
|
def getValidator(name):
|
||||||
return requests.get("http://www.oebb.at/__ressources/system/stationsHafas.jsp?q=%s" % urllib.parse.quote(name)).text
|
return HTTPClient().get("http://www.oebb.at/__ressources/system/stationsHafas.jsp?q=%s" % urllib.parse.quote(name)).text
|
||||||
|
|
||||||
def validateName(name):
|
def validateName(name):
|
||||||
stations = json.loads(getValidator(name))
|
stations = json.loads(getValidator(name))
|
||||||
|
|
Loading…
Reference in a new issue