Spaces:
Build error
Build error
Duplicate from Davis/twitter_scraper
Browse filesCo-authored-by: Davis David <Davis@users.noreply.huggingface.co>
- .gitattributes +27 -0
- README.md +47 -0
- app.py +65 -0
- requirements.txt +3 -0
- twitter.jpg +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Twitter_scraper
|
| 3 |
+
emoji: 🐠
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: red
|
| 6 |
+
sdk: streamlit
|
| 7 |
+
app_file: app.py
|
| 8 |
+
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
duplicated_from: Davis/twitter_scraper
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# Configuration
|
| 14 |
+
|
| 15 |
+
`title`: _string_
|
| 16 |
+
Display title for the Space
|
| 17 |
+
|
| 18 |
+
`emoji`: _string_
|
| 19 |
+
Space emoji (emoji-only character allowed)
|
| 20 |
+
|
| 21 |
+
`colorFrom`: _string_
|
| 22 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 23 |
+
|
| 24 |
+
`colorTo`: _string_
|
| 25 |
+
Color for Thumbnail gradient (red, yellow, green, blue, indigo, purple, pink, gray)
|
| 26 |
+
|
| 27 |
+
`sdk`: _string_
|
| 28 |
+
Can be either `gradio`, `streamlit`, or `static`
|
| 29 |
+
|
| 30 |
+
`sdk_version` : _string_
|
| 31 |
+
Only applicable for `streamlit` SDK.
|
| 32 |
+
See [doc](https://hf.co/docs/hub/spaces) for more info on supported versions.
|
| 33 |
+
|
| 34 |
+
`app_file`: _string_
|
| 35 |
+
Path to your main application file (which contains either `gradio` or `streamlit` Python code, or `static` html code).
|
| 36 |
+
Path is relative to the root of the repository.
|
| 37 |
+
|
| 38 |
+
`models`: _List[string]_
|
| 39 |
+
HF model IDs (like "gpt2" or "deepset/roberta-base-squad2") used in the Space.
|
| 40 |
+
Will be parsed automatically from your code if not specified here.
|
| 41 |
+
|
| 42 |
+
`datasets`: _List[string]_
|
| 43 |
+
HF dataset IDs (like "common_voice" or "oscar-corpus/OSCAR-2109") used in the Space.
|
| 44 |
+
Will be parsed automatically from your code if not specified here.
|
| 45 |
+
|
| 46 |
+
`pinned`: _boolean_
|
| 47 |
+
Whether the Space stays on top of your list.
|
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import twint
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# add banner image
|
| 7 |
+
st.header("Data Scraper App")
|
| 8 |
+
st.image('twitter.jpg')
|
| 9 |
+
st.subheader('''
|
| 10 |
+
A simple app to scrap data from Twitter.
|
| 11 |
+
''')
|
| 12 |
+
|
| 13 |
+
# form to collect searcy query and other conditions
|
| 14 |
+
my_form = st.form(key='Twitter_form')
|
| 15 |
+
search_query = my_form.text_input('Input your search query')
|
| 16 |
+
data_limit = my_form.slider('How many tweets do you want to get?',
|
| 17 |
+
10,
|
| 18 |
+
3000,
|
| 19 |
+
value= 100,
|
| 20 |
+
step=10)
|
| 21 |
+
|
| 22 |
+
output_csv = my_form.radio('Save data to a CSV file?',
|
| 23 |
+
['Yes', 'No'])
|
| 24 |
+
file_name = my_form.text_input('Name the CSV file:')
|
| 25 |
+
submit = my_form.form_submit_button(label='Search')
|
| 26 |
+
|
| 27 |
+
# function to show output in pandas dataframe with specific folumns
|
| 28 |
+
def twint_to_pd(columns):
|
| 29 |
+
return twint.output.panda.Tweets_df[columns]
|
| 30 |
+
|
| 31 |
+
# configure twint to serach the query
|
| 32 |
+
if submit:
|
| 33 |
+
config = twint.Config()
|
| 34 |
+
config.Search = search_query
|
| 35 |
+
config.Limit = data_limit
|
| 36 |
+
config.Pandas = True
|
| 37 |
+
if output_csv == "Yes":
|
| 38 |
+
config.Store_csv = True
|
| 39 |
+
config.Output = '{}.csv'.format(file_name)
|
| 40 |
+
twint.run.Search(config)
|
| 41 |
+
|
| 42 |
+
st.subheader("Results: Sample Data")
|
| 43 |
+
if output_csv == "Yes":
|
| 44 |
+
# show data in pandas dataframe
|
| 45 |
+
data = pd.read_csv('{}.csv'.format(file_name),usecols=['date','username','tweet'])
|
| 46 |
+
st.table(data)
|
| 47 |
+
else:
|
| 48 |
+
data = twint_to_pd(["date","username","tweet"])
|
| 49 |
+
st.table(data)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
#download the dataframe
|
| 53 |
+
@st.cache
|
| 54 |
+
def convert_df(df):
|
| 55 |
+
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
| 56 |
+
return df.to_csv().encode('utf-8')
|
| 57 |
+
|
| 58 |
+
csv = convert_df(data)
|
| 59 |
+
|
| 60 |
+
st.download_button(
|
| 61 |
+
label="Download scrapped data as CSV",
|
| 62 |
+
data=csv,
|
| 63 |
+
file_name='{}.csv'.format(file_name),
|
| 64 |
+
mime='text/csv',
|
| 65 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==1.2.5
|
| 2 |
+
streamlit==1.2.0
|
| 3 |
+
twint==2.1.20
|
twitter.jpg
ADDED
|