2020-09-02 22:39:37 +02:00
|
|
|
import folium
|
|
|
|
import requests
|
2020-09-02 22:54:09 +02:00
|
|
|
import json
|
2020-09-06 13:07:48 +02:00
|
|
|
import subprocess
|
2020-10-07 19:18:42 +02:00
|
|
|
from datetime import datetime
|
|
|
|
from glob import glob
|
2020-09-02 22:39:37 +02:00
|
|
|
|
2020-10-08 18:53:06 +02:00
|
|
|
def application():
|
|
|
|
#create map object
|
|
|
|
m = folium.Map(location=[52.516190, 13.377693], tiles='Stamen Toner',zoom_start=13, zoom_control=False, max_zoom=25)
|
|
|
|
|
|
|
|
#make api request (writes api responses to json)
|
|
|
|
|
|
|
|
subprocess.call(['sh','./scooter_locations.sh'])
|
|
|
|
|
|
|
|
#import scooter data
|
|
|
|
|
|
|
|
scooter_counter = 1
|
|
|
|
|
|
|
|
for file in glob('Scooters/*.json'):
|
|
|
|
print ('importing data of scooter nr.' + str(scooter_counter) + '/10')
|
|
|
|
with open(file, 'r') as scooter_location:
|
|
|
|
location_data=scooter_location.read()
|
|
|
|
#print(location_data)
|
|
|
|
location_data_json = json.loads(location_data)
|
|
|
|
#print(location_data_json)
|
|
|
|
lat = location_data_json['data']['attributes']['lat']
|
|
|
|
#print(lat)
|
|
|
|
lng = location_data_json['data']['attributes']['lng']
|
|
|
|
#print(lng)
|
|
|
|
print('imported. moving on...')
|
|
|
|
|
|
|
|
#create markers for scooter
|
|
|
|
print('creating marker for scooter nr.' + str(scooter_counter) + '/10')
|
|
|
|
folium.Marker([lat,lng],
|
2020-10-09 10:53:09 +02:00
|
|
|
popup='<strong>ARTWORK_TITLE<br>short descriptive one liner about the work<strong/>',
|
2020-10-08 18:53:06 +02:00
|
|
|
tooltip='ARTIST_NAME_HERE',
|
2020-10-09 10:53:09 +02:00
|
|
|
icon=folium.Icon(color='purple', icon='remove')).add_to(m)
|
2020-10-08 18:53:06 +02:00
|
|
|
print('created. moving on...')
|
|
|
|
scooter_counter = scooter_counter+1
|
|
|
|
|
|
|
|
#generate map.html
|
|
|
|
m.save('map.html')
|
|
|
|
#adding mobile support
|
|
|
|
m.get_root().header.add_child(folium.Element(
|
|
|
|
'<meta name="viewport" content="width=device-width,'
|
|
|
|
' initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />'
|
|
|
|
))
|
|
|
|
|
|
|
|
#saving timestamp
|
|
|
|
print('generating timestamp')
|
|
|
|
with open('datetime.txt', 'w') as timestamp:
|
|
|
|
timestamp.write(str(datetime.now()))
|
|
|
|
print('finished!')
|
|
|
|
|
|
|
|
application()
|