Last active
May 3, 2019 17:07
-
-
Save Ben-Ro/4d6337b8921e32ed2c93046feb8fb795 to your computer and use it in GitHub Desktop.
Ein crawler der von https://fridaysforfuture.de/streiktermine/ die aktuell gelisteten Streiks in ein JS umwandelt, welches auf der leaflet Karte angezeigt werden kann.
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 | |
geolocator = Nominatim(user_agent="FridaysforFuture.de Streikkarte") | |
url = 'https://fridaysforfuture.de/streiktermine/' | |
html = requests.get(url).content | |
df_list = pd.read_html(html) | |
df = df_list[0] | |
i = 0 | |
import codecs | |
file = codecs.open("/var/www/mapdata.js", "w", "utf-8") | |
while i < len(df): | |
row = df.iloc[i] | |
i +=1 | |
#print row.to_string(index=False) | |
rs = row.to_string(index=False) | |
stadt = u"{0}".format(rs[1:rs.find(",")]) | |
#print(stadt) | |
rest = rs[rs.find(",")+2: len(rs)] | |
time = rest[0: rest.find(",")] | |
place = rest[rest.find(",")+2:len(rest)] | |
location = geolocator.geocode(stadt) | |
try: | |
geo = ((location.latitude, location.longitude)) | |
except: | |
print("error:") | |
print(stadt) | |
#js.write("L.marker(["+str(geo[0])+","+str(geo[1])+"]).addTo(map).bindPopup('<b>"+stadt+ "</b></br>" + time + "<br>"+ place +"');") | |
out = ("L.marker(["+str(geo[0])+","+str(geo[1])+"]).addTo(map).bindPopup('<b>"+stadt+ "</b></br>" + time + "<br>"+ place +"');") | |
file.write(out) | |
#print(stadt) | |
file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment