-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.py
More file actions
36 lines (29 loc) · 1.11 KB
/
Copy pathdashboard.py
File metadata and controls
36 lines (29 loc) · 1.11 KB
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
import streamlit as st
import snscrape.modules.twitter as sntwitter
import pandas as pd
from datetime import datetime, timedelta
st.title("Sikkim Landslide Twitter Updates")
keywords = [
"Sikkim landslide", "Teesta flood", "Chungthang", "Sikkim rescue",
"#SikkimLandslide", "#Teesta", "#SikkimFlood", "Sikkim missing"
]
search_query = " OR ".join(keywords) + f" since:{(datetime.utcnow()-timedelta(days=3)).strftime('%Y-%m-%d')}"
max_tweets = 100
tweets = []
for tweet in sntwitter.TwitterSearchScraper(search_query).get_items():
tweets.append({
"Date": tweet.date.strftime("%Y-%m-%d %H:%M"),
"User": tweet.user.username,
"Text": tweet.content,
"Link": tweet.url
})
if len(tweets) >= max_tweets:
break
df = pd.DataFrame(tweets)
if len(df) > 0:
st.write(f"Showing {len(df)} most recent tweets with relevant keywords:")
st.dataframe(df[["Date", "User", "Text"]])
for i, row in df.iterrows():
st.markdown(f"- **[{row['User']}]({row['Link']})**: {row['Text']}")
else:
st.write("No recent tweets found. Try again later or with different keywords.")