Last active
May 15, 2019 21:05
-
-
Save Ben-Ro/90f3fdfc307a1a4e6c259d355c273a3d to your computer and use it in GitHub Desktop.
fff-map.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import pandas as pd | |
from geopy.geocoders import Nominatim | |
import datetime | |
print(datetime.datetime.now())#for logging reasons | |
geolocator = Nominatim(user_agent="fridaysforfuture.de/streiktermine map data generator") | |
url = 'https://fridaysforfuture.de/24mai/' | |
html = requests.get(url, verify=False).content | |
df_list = pd.read_html(html) | |
df = df_list[0] | |
i = 1 #first row is of the table is not an event at the /24mai page, at /streiktermine i=0 | |
while i < len(df): | |
row = df.iloc[i] | |
i +=1 | |
rs = row.to_string(index=False) | |
stadt = u"{0}".format(rs[1:rs.find(",")])#input is: stadt, time, place | |
rest = rs[rs.find(",")+2: len(rs)]#+2 because of one whitespace after , | |
time = rest[0: rest.find(",")] | |
place = rest[rest.find(",")+2:len(rest)]#+2 because of one whitespace after , | |
location = geolocator.geocode(stadt + ", Germany")#without Germany the results are sometimes strange | |
try: | |
geo = ((location.latitude, location.longitude)) | |
except: | |
print("error") | |
geo = ((0,0)) | |
print("Search: "+ stadt + ", Germany | Result: " + str(geo[0]) + str(geo[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment