File size: 2,757 Bytes
81b6f31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import streamlit as st

# Function to parse the data for a specific state using its two-letter code
def parse_state_data(data, state_code):
    state_data = {}
    current_category = None

    for line in data:
        line = line.strip()
        if line.startswith(state_code + ":"):
            state_data["Name"] = line[len(state_code) + 1:]
        elif line.startswith("# Large Companies"):
            current_category = "Large Companies"
            state_data[current_category] = []
        elif line.startswith("# Cities"):
            current_category = "Cities"
            state_data[current_category] = []
        elif line.startswith("# Hospitals"):
            current_category = "Hospitals"
            state_data[current_category] = []
        elif line.startswith("#"):
            current_category = None
        elif current_category:
            state_data[current_category].append(line)

    return state_data

# Function to create a search URL for Wikipedia:
def create_search_url_wikipedia(query):
    base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
    return base_url + query.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')

# Function to create a search URL for YouTube:
def create_search_url_youtube(query):
    base_url = "https://www.youtube.com/results?search_query="
    return base_url + query.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')

# Read and parse the data from the text file
with open("states_data.txt", "r") as file:
    data = file.readlines()

# Streamlit page configuration
st.set_page_config(page_title="State Data", layout="wide")

# Main title
st.title("Top Five Lists for Different States 🏙️")

# Select a state using a two-letter code
selected_state = st.selectbox("Select a State:", ["MA: Massachusetts", "CA: California", "WA: Washington"])

# Parse the data for the selected state
state_code = selected_state.split(":")[0]
state_data = parse_state_data(data, state_code)

# Display the state name
st.header(f"{state_data['Name']} 🏆")

# Display the top five lists
for category, nominees in state_data.items():
    if category != "Name":
        st.subheader(f"{category}")
        with st.expander(f"View {category} Nominees"):
            for nominee in nominees[:5]:  # Show only the top five
                col1, col2, col3 = st.columns([4, 1, 1])
                with col1:
                    st.markdown(f"* {nominee}")
                with col2:
                    st.markdown(f"[Wikipedia]({create_search_url_wikipedia(nominee)})")
                with col3:
                    st.markdown(f"[YouTube]({create_search_url_youtube(nominee)})")

# Footer
st.caption("Source: Wikipedia and YouTube")