Spaces:
Runtime error
Runtime error
Commit
•
86f79dd
1
Parent(s):
360bf8a
Testing get_tweets
Browse files
app.py
CHANGED
@@ -3,6 +3,26 @@ import pandas as pd
|
|
3 |
import twint
|
4 |
import nest_asyncio
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
st.title('Test')
|
7 |
|
8 |
with st.form("my_form"):
|
@@ -13,6 +33,8 @@ with st.form("my_form"):
|
|
13 |
# Every form must have a submit button.
|
14 |
submitted = st.form_submit_button("Submit")
|
15 |
if submitted:
|
16 |
-
st.write("user", user, "n_tweets", n_tweets)
|
|
|
|
|
17 |
|
18 |
st.write("Outside the form")
|
|
|
3 |
import twint
|
4 |
import nest_asyncio
|
5 |
|
6 |
+
# Function to make this easy for ourselves:
|
7 |
+
def get_tweets(username, limit=500, save_name=None):
|
8 |
+
nest_asyncio.apply() # Helps avoid RuntimeError: This event loop is already running
|
9 |
+
|
10 |
+
# Setup config
|
11 |
+
c = twint.Config() # Create a config object to store our settings
|
12 |
+
c.Limit = limit # Max number of tweets to fetch (increments of 20)
|
13 |
+
c.Username = username # User of interest
|
14 |
+
c.Pandas = True # Store tweets in a dataframe
|
15 |
+
c.Hide_output = True # Avoid printing out tweets
|
16 |
+
|
17 |
+
# Run the seearch
|
18 |
+
twint.run.Search(c)
|
19 |
+
|
20 |
+
# Get the results and optionally save to a file as well
|
21 |
+
df = twint.storage.panda.Tweets_df
|
22 |
+
if save_name != None:
|
23 |
+
df.to_csv(save_name)
|
24 |
+
return df
|
25 |
+
|
26 |
st.title('Test')
|
27 |
|
28 |
with st.form("my_form"):
|
|
|
33 |
# Every form must have a submit button.
|
34 |
submitted = st.form_submit_button("Submit")
|
35 |
if submitted:
|
36 |
+
st.write("Fetching user", user, "n_tweets", n_tweets)
|
37 |
+
tweets = get_tweets(user, limit=n_tweets)
|
38 |
+
st.write(st.dataframe(tweets.head()))
|
39 |
|
40 |
st.write("Outside the form")
|