This repository has been archived by the owner on Jan 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
70 lines (56 loc) · 2.02 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from bs4 import BeautifulSoup
from urllib import parse
from geopy.geocoders import Nominatim
from geopy import distance
import requests
def get_location(query):
geolocator = Nominatim(user_agent="vaccinator")
location = geolocator.geocode(query)
if location is not None:
return location.latitude, location.longitude
else:
return False
def get_distance(source, destination):
if destination[0] is None or destination[1] is None:
destination = source
return distance.distance(source, destination).km
def get_google_results(pos=0):
cookies = {"CONSENT": "YES+DE.de+20160410-02-0"}
url = f"https://www.google.com/search?q=site:impfterminmanagement.de&start={pos}"
response = requests.get(url, cookies=cookies).text
body = BeautifulSoup(response, 'html.parser')
entries = body.find_all("a")
urls = [
parse.parse_qs(entry["href"])["/url?q"][0] for entry in entries
if entry["href"].startswith("/url")
]
return urls
def get_doctors():
doctors = []
pos = 0
while True:
results = get_google_results(pos)
results = [result for result in results if "impfterminmanagement.de/praxis" in result]
if not results:
break
pos += 10
doctors.extend(results)
return doctors
def get_clinic_details(url) -> dict:
res = requests.get(url)
soup = BeautifulSoup(res.text, "html.parser")
if not "Unbekannt" in soup.find("h1", class_="title").text:
infotext = soup.select(".alert-info")[0].text.splitlines()
id = res.url.split("/")[4]
name = infotext[6].strip()
print(f"found: {name}")
address = infotext[7].strip() + ", " + infotext[8].strip() + " " + infotext[9].strip()
location = get_location(address)
details = {
"name": name,
"id": id,
"address": address,
"latitude": None if not location else location[0],
"longitude": None if not location else location[1]
}
return details