#!/usr/local/bin/python from firebase_admin import credentials, firestore, initialize_app from requests import get as api_get from time import time as timestamp from datetime import datetime cert_path = "secrets/icl-iot-weather-firebase-adminsdk-d2a8f-577125a0ff.json" cred = credentials.Certificate(cert_path) initialize_app(cred) firestore_db = firestore.client() 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://{str(request_endpoint)}?q={str(request_city)}&appid={str(api_key)}".split('\n')[0] api_rsp = api_get(request_url) print(api_rsp.text) current_weather_data = { timestamp": timestamp.now(), "datetime": datetime.now(), "temp": current_temp_celcius, "humidity": current_humidity_pct, "cloud": current_cloud_pct, "wind": current_wind_ms, "rain_1h": rain_mm_1h, "is_test": is_test" } snapshots = list(firestore_db.collection(u'weather_data').get()) for snapshot in snapshots: print(snapshot.to_dict()) #firestore_db.collection(u'songs').add({'song': 'Imagine', 'artist': 'John Lennon'}