|
| 1 | +#!/usr/bin/env python3 |
| 2 | +""" |
| 3 | +Celestial Events Calendar |
| 4 | +Displays upcoming celestial events from a static dataset |
| 5 | +Created for issue #618 |
| 6 | +""" |
| 7 | + |
| 8 | +from datetime import datetime, timedelta |
| 9 | + |
| 10 | +def get_celestial_events(): |
| 11 | + """Returns a list of celestial events with dates and details""" |
| 12 | + events = [ |
| 13 | + {"date": "2025-10-25", "type": "Eclipse", "name": "Partial Solar Eclipse", |
| 14 | + "description": "Visible in North America", "visibility": "Regional"}, |
| 15 | + {"date": "2025-11-17", "type": "Meteor Shower", "name": "Leonids Meteor Shower", |
| 16 | + "description": "Peak viewing after midnight", "visibility": "Global"}, |
| 17 | + {"date": "2025-12-15", "type": "Meteor Shower", "name": "Geminids Meteor Shower", |
| 18 | + "description": "Best meteor shower of the year", "visibility": "Global"}, |
| 19 | + {"date": "2026-01-04", "type": "Meteor Shower", "name": "Quadrantids Meteor Shower", |
| 20 | + "description": "Active from late December to mid-January", "visibility": "Northern Hemisphere"}, |
| 21 | + {"date": "2026-02-17", "type": "Eclipse", "name": "Total Lunar Eclipse", |
| 22 | + "description": "Visible from Americas, Europe, and Africa", "visibility": "Multi-continental"}, |
| 23 | + {"date": "2026-03-20", "type": "Alignment", "name": "Spring Equinox", |
| 24 | + "description": "Equal day and night", "visibility": "Global"}, |
| 25 | + {"date": "2026-04-22", "type": "Meteor Shower", "name": "Lyrids Meteor Shower", |
| 26 | + "description": "One of the oldest known meteor showers", "visibility": "Global"}, |
| 27 | + {"date": "2026-05-06", "type": "Meteor Shower", "name": "Eta Aquarids Meteor Shower", |
| 28 | + "description": "Debris from Halley's Comet", "visibility": "Southern Hemisphere"}, |
| 29 | + {"date": "2026-06-21", "type": "Alignment", "name": "Summer Solstice", |
| 30 | + "description": "Longest day of the year in Northern Hemisphere", "visibility": "Global"}, |
| 31 | + {"date": "2026-08-12", "type": "Eclipse", "name": "Total Solar Eclipse", |
| 32 | + "description": "Path of totality crosses Greenland, Iceland, and Spain", "visibility": "Regional"}, |
| 33 | + {"date": "2026-08-13", "type": "Meteor Shower", "name": "Perseids Meteor Shower", |
| 34 | + "description": "Most popular meteor shower of the year", "visibility": "Global"}, |
| 35 | + {"date": "2026-09-22", "type": "Alignment", "name": "Autumn Equinox", |
| 36 | + "description": "Equal day and night", "visibility": "Global"}, |
| 37 | + ] |
| 38 | + return events |
| 39 | + |
| 40 | +def filter_events_by_type(events, event_type=None): |
| 41 | + """Filter events by type""" |
| 42 | + if event_type: |
| 43 | + return [e for e in events if e["type"].lower() == event_type.lower()] |
| 44 | + return events |
| 45 | + |
| 46 | +def filter_events_by_date_range(events, start_date=None, end_date=None): |
| 47 | + """Filter events within a date range""" |
| 48 | + filtered = [] |
| 49 | + for event in events: |
| 50 | + event_date = datetime.strptime(event["date"], "%Y-%m-%d") |
| 51 | + if start_date and event_date < start_date: |
| 52 | + continue |
| 53 | + if end_date and event_date > end_date: |
| 54 | + continue |
| 55 | + filtered.append(event) |
| 56 | + return filtered |
| 57 | + |
| 58 | +def display_events(events): |
| 59 | + """Display celestial events in a formatted manner""" |
| 60 | + if not events: |
| 61 | + print("No events found matching your criteria.") |
| 62 | + return |
| 63 | + |
| 64 | + print("\n" + "="*60) |
| 65 | + print("UPCOMING CELESTIAL EVENTS".center(60)) |
| 66 | + print("="*60 + "\n") |
| 67 | + |
| 68 | + for event in events: |
| 69 | + print(f"Date: {event['date']}") |
| 70 | + print(f"Type: {event['type']}") |
| 71 | + print(f"Event: {event['name']}") |
| 72 | + print(f"Details: {event['description']}") |
| 73 | + print(f"Visibility: {event['visibility']}") |
| 74 | + print("-" * 60) |
| 75 | + |
| 76 | +def main(): |
| 77 | + """Main function to run the celestial events calendar""" |
| 78 | + events = get_celestial_events() |
| 79 | + |
| 80 | + # Filter for upcoming events (from today onwards) |
| 81 | + today = datetime.now() |
| 82 | + upcoming_events = filter_events_by_date_range(events, start_date=today) |
| 83 | + |
| 84 | + print("\nWelcome to the Celestial Events Calendar!") |
| 85 | + print(f"Current Date: {today.strftime('%Y-%m-%d')}\n") |
| 86 | + |
| 87 | + # Display all upcoming events |
| 88 | + display_events(upcoming_events) |
| 89 | + |
| 90 | + # Example: Display only meteor showers |
| 91 | + print("\n\nUPCOMING METEOR SHOWERS:") |
| 92 | + meteor_showers = filter_events_by_type(upcoming_events, "Meteor Shower") |
| 93 | + display_events(meteor_showers) |
| 94 | + |
| 95 | +if __name__ == "__main__": |
| 96 | + main() |
0 commit comments