Skip to content

Instantly share code, notes, and snippets.

@Vini2
Created March 1, 2020 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vini2/1249594d23ab1e11b5bec36c62870d57 to your computer and use it in GitHub Desktop.
Save Vini2/1249594d23ab1e11b5bec36c62870d57 to your computer and use it in GitHub Desktop.
Pulling twitter data
import tweepy as tw
import pandas as pd
import json
# App Auth
consumer_key = 'XXX'
consumer_secret = 'XXX'
access_key = 'XXX'
access_secret = 'XXX'
# Initialize API
auth = tw.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tw.API(auth, wait_on_rate_limit=True)
# Search terms
search_words = ["#coronavirus", "#COVID19", "#CoronavirusOutbreak"]
date_since = "2020-02-01"
# Collect tweets
tweets = tw.Cursor(api.search,
q=search_words,
lang="en",
since=date_since, tweet_mode='extended',
include_rts=True).items(1000)
tweets_arr = []
# Iterate and print tweets
for tweet in tweets:
tweets_arr.append(tweet._json)
print("Done")
with open("data.json", "w+") as output:
output.write(json.dumps(tweets_arr))
@astrywi
Copy link

astrywi commented Apr 13, 2020

ini untuk python versi brp yah?

@Vini2
Copy link
Author

Vini2 commented Apr 14, 2020

ini untuk python versi brp yah?

I don't understand what you mean. If you are asking for the Python version, it is Python 3.7.

@astrywi
Copy link

astrywi commented Apr 14, 2020

thankyou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment