From cc2c776d392730365f2f9e7379e31203dae98b21 Mon Sep 17 00:00:00 2001 From: bryce Date: Tue, 22 Jul 2025 19:32:41 +1200 Subject: [PATCH] finished py script --- generate_earthquakes.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/generate_earthquakes.py b/generate_earthquakes.py index 379c1be..b6ff183 100644 --- a/generate_earthquakes.py +++ b/generate_earthquakes.py @@ -140,4 +140,39 @@ def generate_html(quakes, output_file="geonet_earthquakes.html", css_file="style """ - + with open(output_file, "w", encoding="utf-8") as f: + f.write(html_content) + print(f"Generated {output_file} with {len(quakes)} earthquakes.) + + if __name__ == "__main__": + output_html_file = "geonet_earthquakes_list.html" + css_file_name = "style.css" + min_mmi_threshold = 8 + earthquake_limit = 20 + filter_today_only = True + update_interval_minutes = 1 + + print(f"Starting Geonet Earthquake Display Generator. HTML file: `{output_html_file}`") + print(f"Updating every {update_interval_minutes} minute(s).") + print(f"Filtering for MMI {min_mmi_threshold}+, max {earthquake_limit} from today (NZT), including deleted events from today.") + + latest_quakes = get_earthquakes( + min_mmi=min_mmi_threshold, + limmit=earthquake_limit, + from_today_only=filter_today_only + ) + generate_html(latest_quakes, output_html_file, css_file_name) + + # continuous updater loop untl ctrl+C + import time + while True: + try: + latest_quakes = get_earthquakes( + min_mmi=min_mmi_threshold, + limit=earthquake_limit, + from_today_only=filter_today_only + ) + generate_html(latest_quakes, output_html_file, css_file_name) + except Exception as e: + print(f"An error occurred during update: {e}") + time.sleep(update_interval_minutes * 60)