# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3 (ipykernel)
#     language: python
#     name: python3
# ---

# ## Gather recent Twitter data

import tweepy as tw
import datetime
import csv
import pandas as pd

api_key = "tnpWnjHBc1tqXQiA2aVF9kE1C"
api_key_secret = "<KEY>"
access_token = "<KEY>"
access_token_secret = "<KEY>"

auth = tw.OAuthHandler(api_key, api_key_secret)
auth.set_access_token(access_token, access_token_secret)
api = tw.API(auth, wait_on_rate_limit=True)

search_words =  "#Covid19vaccine OR #covid19vaccine OR #covidvaccine OR #COVIDvaccine OR #COVID-19 Vaccine OR #COVID-19Vaccine"


cursor = tw.Cursor(api.search_tweets,
                   q=search_words,
                   lang="en",
                  result_type="recent")
cursor

tweets = cursor.items(100)
tweets

#what information we need from tweets
tweet_details=[[tweet.text,tweet.user.screen_name,tweet.user.location,tweet.created_at.strftime("%d-%b-%Y")] for tweet in tweets]

tweet_df=pd.DataFrame(data=tweet_details,columns=['text','user','location','date'])
tweet_df

tweet_df=tweet_df[tweet_df['location'].str.contains('USA')|tweet_df['location'].str.contains('United States')]
tweet_df.head()

#rename to different names each time pulling, starting with pull
tweet_df.to_csv("pull14.csv",index=False,encoding='utf-8')
#then we combined all the pull*.csv in .data\recent_tw.csv



StarcoderdataJupyterScriptsDedupFiltered