From 552c3d189970366849f8672a605f530edbd4e5c4 Mon Sep 17 00:00:00 2001 From: eagleshot <****@****.com> Date: Sun, 11 Feb 2024 14:40:04 +0100 Subject: [PATCH] Move modules to separate folder --- fileserver.py => Modules/fileserver.py | 0 settings.py => Modules/settings.py | 0 sim7600x.py => Modules/sim7600x.py | 0 witty_pi_4.py => Modules/witty_pi_4.py | 0 Webapp/streamlit_app.py | 9 +++--- sunrise_test.py | 45 -------------------------- 6 files changed, 5 insertions(+), 49 deletions(-) rename fileserver.py => Modules/fileserver.py (100%) rename settings.py => Modules/settings.py (100%) rename sim7600x.py => Modules/sim7600x.py (100%) rename witty_pi_4.py => Modules/witty_pi_4.py (100%) delete mode 100644 sunrise_test.py diff --git a/fileserver.py b/Modules/fileserver.py similarity index 100% rename from fileserver.py rename to Modules/fileserver.py diff --git a/settings.py b/Modules/settings.py similarity index 100% rename from settings.py rename to Modules/settings.py diff --git a/sim7600x.py b/Modules/sim7600x.py similarity index 100% rename from sim7600x.py rename to Modules/sim7600x.py diff --git a/witty_pi_4.py b/Modules/witty_pi_4.py similarity index 100% rename from witty_pi_4.py rename to Modules/witty_pi_4.py diff --git a/Webapp/streamlit_app.py b/Webapp/streamlit_app.py index 186a372..19f849b 100644 --- a/Webapp/streamlit_app.py +++ b/Webapp/streamlit_app.py @@ -1,4 +1,5 @@ """Webserver for the Eagleshot GlacierCam - https://github.com/Eagleshot/GlacierCam""" + import sys from io import BytesIO from datetime import datetime @@ -10,11 +11,11 @@ import pytz from suntime import Sun, SunTimeException import requests +from Modules.settings import Settings +import Modules.fileserver as fs -sys.path.append(str(Path(__file__).resolve().parent.parent)) # Add the parent directory to sys.path - -from settings import Settings -import fileserver as fs +# Add parent directory to system path to import the modules +sys.path.append(str(Path(__file__).resolve().parent.parent)) # Login status if "userIsLoggedIn" not in st.session_state: diff --git a/sunrise_test.py b/sunrise_test.py deleted file mode 100644 index b3f8721..0000000 --- a/sunrise_test.py +++ /dev/null @@ -1,45 +0,0 @@ -import random -import json -import time -import datetime -import requests -import pytz -import suntime - -# Generate 100 random locations -locations = [] -for i in range(10): - locations.append((random.uniform(-90, 90), random.uniform(-180, 180))) - -# Get sunrise and sunset times from OpenWeatherMap API -api_key = "e50a51592ca62560405aad1b5fe3a825" - -for lat, lon in locations: - - # OpenWeatherMap API - url = f"https://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid={api_key}" - response = requests.get(url, timeout=5) - data = json.loads(response.text) - today_sr_openweathermap = data["sys"]["sunrise"] - today_sr_openweathermap = datetime.datetime.fromtimestamp(today_sr_openweathermap) - today_ss_openweathermap = data["sys"]["sunset"] - today_ss_openweathermap = datetime.datetime.fromtimestamp(today_ss_openweathermap) - - # Sunrise and sunset times - sun = suntime.Sun(lat, lon) - try: - today_sr_calculated = sun.get_sunrise_time() - today_sr_calculated = pytz.utc.localize(today_sr_calculated) # Convert to offset-aware datetime object - today_ss_calculated = sun.get_sunset_time() - today_ss_calculated = pytz.utc.localize(today_ss_calculated) # Convert to offset-aware datetime object - except suntime.SunTimeException as e: - print("No sunrise today") - continue - - # Check if the results are within 1 minute of each other - if not abs(today_sr_openweathermap - today_sr_calculated) < datetime.timedelta(minutes=1): - print(f"Sunrise times do not match for location {lat}, {lon}.") - print(f"OpenWeatherMap API: {today_sr_openweathermap}") - print(f"Calculated: {today_sr_calculated}") - - time.sleep(1)