27 lines
826 B
Python
27 lines
826 B
Python
from firebase_admin import credentials, firestore, initialize_app
|
|
from requests import get as api_get
|
|
|
|
cert_path = "secrets/icl-iot-weather-firebase-adminsdk-d2a8f-577125a0ff.json"
|
|
cred = credentials.Certificate(cert_path)
|
|
initialize_app(cred)
|
|
|
|
firestore_db = firestore.client()
|
|
|
|
|
|
#firestore_db.collection(u'songs').add({'song': 'Imagine', 'artist': 'John Lennon'}
|
|
with open("secrets/weather_api_key.txt", "r") as api_key_file:
|
|
api_key = api_key_file.read()
|
|
|
|
request_endpoint = "api.openweathermap.org/data/2.5/weather"
|
|
request_city = "London"
|
|
|
|
request_url = f"https://{request_endpoint}?q={request_city}&appid={api_key}"
|
|
print(request_url)
|
|
|
|
api_rsp = api_get(request_url)
|
|
print(api_rsp.text)
|
|
|
|
# snapshots = list(firestore_db.collection(u'weather_data').get())
|
|
# for snapshot in snapshots:
|
|
# print(snapshot.to_dict())
|