CoolFace
Apppublic

ProfessionalServices/specialdate

sourceHugging Facemitupdated 7mo agoView on Hugging Face
0likes
app.py73 linesDownload Raw Back to root
1import streamlit as st2import httpx3from datetime import datetime4 5# Wikipedia API base URL6BASE_URL = "https://en.wikipedia.org/api/rest_v1/feed/onthisday"7 8st.set_page_config(page_title="On This Day", page_icon="๐Ÿ“…")9 10st.title("๐Ÿ“… On This Day")11st.markdown("Discover historical **events** and **holidays** for any selected date.")12 13# Date selector14date = st.date_input("Select a Date", value=datetime.today())15formatted_date = date.strftime("%B %d")16 17if st.button("Get Details"):18 19    month = date.month20    day = date.day21 22    headers = {23        "User-Agent": "OnThisDayStreamlitApp/1.0 (https://huggingface.co)"24    }25 26    try:27        with st.spinner("Fetching data from Wikipedia..."):28 29            # Fetch Events30            events_response = httpx.get(31                f"{BASE_URL}/events/{month}/{day}",32                headers=headers,33                timeout=1034            )35            events_response.raise_for_status()36            events_data = events_response.json()37 38            # Fetch Holidays39            holidays_response = httpx.get(40                f"{BASE_URL}/holidays/{month}/{day}",41                headers=headers,42                timeout=1043            )44            holidays_response.raise_for_status()45            holidays_data = holidays_response.json()46 47        events = [48            f"{event['year']}: {event['text']}"49            for event in events_data.get("events", [])[:10]50        ]51 52        holidays = [53            holiday["text"]54            for holiday in holidays_data.get("holidays", [])55        ]56 57        st.success(f"Results for {formatted_date}")58 59        if events:60            st.subheader("๐Ÿ“œ Historical Events")61            for event in events:62                st.write(f"- {event}")63 64        if holidays:65            st.subheader("๐ŸŽ‰ Holidays & Observances")66            for holiday in holidays:67                st.write(f"- {holiday}")68 69        if not events and not holidays:70            st.warning("No data available for this date.")71 72    except Exception as e:73        st.error(f"Failed to fetch details: {str(e)}")