opencoil-paracity/website/Speedshow_Map.py

52 lines
1.5 KiB
Python
Raw Normal View History

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
from datetime import datetime
from glob import glob
2020-09-02 22:39:37 +02:00
#create map object
m = folium.Map(location=[52.516190, 13.377693], tiles='Stamen Toner',zoom_start=13, zoom_control=False)
#make api request (writes api responses to json)
2020-09-06 13:07:48 +02:00
subprocess.call(['sh','./scooter_locations.sh'])
2020-09-02 22:39:37 +02:00
2020-09-06 13:07:48 +02:00
#import scooter data
2020-09-02 22:54:09 +02:00
scooter_counter = 1
2020-09-02 22:39:37 +02:00
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...')
2020-09-02 22:39:37 +02:00
#create markers for scooter
print('creating marker for scooter nr.' + str(scooter_counter) + '/10')
folium.Marker([lat,lng],
popup='<strong>ARTIST_NAME + ARTWORK_TITLE<strong/>',
tooltip='ARTIST_NAME_HERE',
icon=folium.Icon(icon='cloud')).add_to(m)
print('created. moving on...')
scooter_counter = scooter_counter+1
2020-09-02 22:39:37 +02:00
#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!')