From ae0eecbea01ec2ac3fb23444262db201cd21d32a Mon Sep 17 00:00:00 2001 From: Miupro Date: Sat, 30 Oct 2021 22:41:07 +0200 Subject: [PATCH] Interactive Map --- apis/interactive_maps.py | 26 +++++++++ apis/sbb.py | 30 +++++++++-- apis/weather.py | 28 ++++++++++ foliummap.html | 113 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 194 insertions(+), 3 deletions(-) create mode 100644 apis/interactive_maps.py create mode 100644 foliummap.html diff --git a/apis/interactive_maps.py b/apis/interactive_maps.py new file mode 100644 index 0000000..972e8d2 --- /dev/null +++ b/apis/interactive_maps.py @@ -0,0 +1,26 @@ +import folium +from folium import plugins +import json + +#OpenStreetMap +m = folium.Map(location=[46.8132, 8.2242], tiles='CartoDB', zoom_start=7.6, min_zoom = 6, max_zoom = 12) + + +# Hard coded location list +location_list = [('Center of Switzerland' , [46.8132, 8.2242]), ('Zermatt', [46.11654, 7.445683])] + +for place, coordinates in location_list: + folium.Marker( + location=coordinates, # coordinates for the marker + popup=place, # pop-up label for the marker + icon=folium.Icon(color="red")#, icon_color = 'red', icon="fa-map-marker-alt", prefix='fa') + ).add_to(m) + + +m.save('foliummap.html') + +html_string = m.get_root().render() +print(html_string) +print('finish') + +return html_string \ No newline at end of file diff --git a/apis/sbb.py b/apis/sbb.py index e72e3fd..bb060f0 100644 --- a/apis/sbb.py +++ b/apis/sbb.py @@ -1,5 +1,6 @@ import tortilla import requests +import pandas as pd class SBBWrapper: @@ -25,7 +26,30 @@ class SBBWrapper: # 'X-Conversation-Id': str(conv_id), } return auth - +""" +sbb=SBBWrapper() +print(sbb.wrapper.get('name':'Bern')) +""" - def get_closest_station(self, station_name): - pass \ No newline at end of file +""" +header_dict = {'api_key' : '814d86a3ffc49c350bb7dcc48cac69b3'} + +response = requests.get('https://journey-maps.api.sbb.ch:443', headers=header_dict) +print(response.text) +""" + + +""" +header_dict = {'api_key' : 'xxxxx'} +response = requests.get('https://journey-pois-int.api.sbb.ch/', headers=header_dict) +print(response) + +""" +"""" + +header_dict = {'key':'yourtest-outdoora-ctiveapi', +'project' : 'api-dev-oa' } +response = requests.get('http://www.outdooractive.com/api', headers=header_dict).json() +print(response) +print('finish') +""" \ No newline at end of file diff --git a/apis/weather.py b/apis/weather.py index e69de29..123d6ee 100644 --- a/apis/weather.py +++ b/apis/weather.py @@ -0,0 +1,28 @@ +import tortilla +import requests + +class WeatherWrapper: + def __init__(self) -> None: + self.wrapper = tortilla.wrap('https://weather.api.sbb.ch/') + self.wrapper.config.headers = self.get_auth() + + def get_auth(self): + token_query = { + 'grant_type': 'client_credentials', + 'client_id': '56bae62c', + 'client_secret': '59603134536c874e47245b4de403e3d3' + } + + #response = requests.post('https://sso-int.sbb.ch/auth/realms/SBB_Public/protocol/openid-connect/token', data=token_query).json() + response = requests.post('https://sso.sbb.ch/auth/realms/SBB_Public/protocol/openid-connect/token', data=token_query).json() + token = response["access_token"] + auth = { + 'Authorization': f"Bearer {token}", + 'X-Contract-Id': 'PLY223P', + # 'X-Conversation-Id': str(conv_id), + } + return auth + +weather = WeatherWrapper() +print('TEST') +print(weather.wrapper.get('2021-07-12T00:00ZP50D:PT30M/sfc_pressure:hPa,msl_pressure:hPa/47.36669,8.54858+47.35209,7.90779/json')) \ No newline at end of file diff --git a/foliummap.html b/foliummap.html new file mode 100644 index 0000000..328db9e --- /dev/null +++ b/foliummap.html @@ -0,0 +1,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + \ No newline at end of file