awacke1 commited on
Commit
81b6f31
·
1 Parent(s): 145a4c4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Function to parse the data for a specific state using its two-letter code
4
+ def parse_state_data(data, state_code):
5
+ state_data = {}
6
+ current_category = None
7
+
8
+ for line in data:
9
+ line = line.strip()
10
+ if line.startswith(state_code + ":"):
11
+ state_data["Name"] = line[len(state_code) + 1:]
12
+ elif line.startswith("# Large Companies"):
13
+ current_category = "Large Companies"
14
+ state_data[current_category] = []
15
+ elif line.startswith("# Cities"):
16
+ current_category = "Cities"
17
+ state_data[current_category] = []
18
+ elif line.startswith("# Hospitals"):
19
+ current_category = "Hospitals"
20
+ state_data[current_category] = []
21
+ elif line.startswith("#"):
22
+ current_category = None
23
+ elif current_category:
24
+ state_data[current_category].append(line)
25
+
26
+ return state_data
27
+
28
+ # Function to create a search URL for Wikipedia:
29
+ def create_search_url_wikipedia(query):
30
+ base_url = "https://www.wikipedia.org/search-redirect.php?family=wikipedia&language=en&search="
31
+ return base_url + query.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
32
+
33
+ # Function to create a search URL for YouTube:
34
+ def create_search_url_youtube(query):
35
+ base_url = "https://www.youtube.com/results?search_query="
36
+ return base_url + query.replace(' ', '+').replace('–', '%E2%80%93').replace('&', 'and')
37
+
38
+ # Read and parse the data from the text file
39
+ with open("states_data.txt", "r") as file:
40
+ data = file.readlines()
41
+
42
+ # Streamlit page configuration
43
+ st.set_page_config(page_title="State Data", layout="wide")
44
+
45
+ # Main title
46
+ st.title("Top Five Lists for Different States 🏙️")
47
+
48
+ # Select a state using a two-letter code
49
+ selected_state = st.selectbox("Select a State:", ["MA: Massachusetts", "CA: California", "WA: Washington"])
50
+
51
+ # Parse the data for the selected state
52
+ state_code = selected_state.split(":")[0]
53
+ state_data = parse_state_data(data, state_code)
54
+
55
+ # Display the state name
56
+ st.header(f"{state_data['Name']} 🏆")
57
+
58
+ # Display the top five lists
59
+ for category, nominees in state_data.items():
60
+ if category != "Name":
61
+ st.subheader(f"{category}")
62
+ with st.expander(f"View {category} Nominees"):
63
+ for nominee in nominees[:5]: # Show only the top five
64
+ col1, col2, col3 = st.columns([4, 1, 1])
65
+ with col1:
66
+ st.markdown(f"* {nominee}")
67
+ with col2:
68
+ st.markdown(f"[Wikipedia]({create_search_url_wikipedia(nominee)})")
69
+ with col3:
70
+ st.markdown(f"[YouTube]({create_search_url_youtube(nominee)})")
71
+
72
+ # Footer
73
+ st.caption("Source: Wikipedia and YouTube")