Last active
November 7, 2019 19:27
-
-
Save karlbeecken/e2f63996f79f239a21d0e593d9bfdd66 to your computer and use it in GitHub Desktop.
map generation for the mobimaterial of FFF Berlin
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") | |
pd.set_option('display.max_colwidth', -1) | |
url = 'https://fridaysforfuture.berlin/mobi-material/' | |
html = requests.get(url).content | |
df_list = pd.read_html(html) | |
df = df_list[0] | |
i = 0 | |
import codecs | |
file = codecs.open("/var/www/html/mapdata-mobi.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("|")]) | |
rest = rs[rs.find("|") + 2: len(rs)] | |
place = rest[0: rest.find("|")] | |
time = rest[rest.find("|") + 2:len(rest)] | |
location = geolocator.geocode(place) | |
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]) + "],{icon:greenIcon}).addTo(map).bindPopup('<b>" + stadt + "</b></br>" + time + "<br>" + place + "');\n") | |
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