Last active
November 10, 2020 09:02
-
-
Save revox/2d9075474cbe0c97ce5210235f3e40bf to your computer and use it in GitHub Desktop.
sixohsix Twittter lib doing a follow on a couple of news accounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Finding topics of interest by using the filtering capablities it offers. | |
import twitter, json, sys, csv | |
# == OAuth Authentication == | |
# The consumer keys can be found on your application's Details | |
# page located at https://dev.twitter.com/apps (under "OAuth settings") | |
# this app is being run by cast laboratory..@CASTlaboratory (4003669463) | |
consumer_key="" | |
consumer_secret="" | |
# After the step above, you will be redirected to your app's page. | |
# Create an access token under the the "Your access token" section | |
access_token="" | |
access_token_secret="" | |
auth = twitter.oauth.OAuth(access_token, access_token_secret,consumer_key, consumer_secret) | |
twitter_api = twitter.Twitter(auth=auth) | |
csvfile = open('3.csv', 'a') | |
csvwriter = csv.writer(csvfile) | |
# what does following a user mean - https://dev.twitter.com/streaming/overview/request-parameters#follow | |
u = "18949452, 612473" | |
print >> sys.stderr, 'Filtering the public timeline for a user="%s"' % (u) | |
# Reference the self.auth parameter | |
twitter_stream = twitter.TwitterStream(auth=twitter_api.auth) | |
# See https://dev.twitter.com/docs/streaming-apis | |
stream = twitter_stream.statuses.filter(follow=u) | |
# For illustrative purposes, when all else fails, search for Justin Bieber | |
# and something is sure to turn up (at least, on Twitter) | |
for tweet in stream: | |
print (tweet['text']) | |
user = tweet['user']['screen_name'] | |
# print (json.dumps(tweet, indent=1)) | |
csvwriter.writerow([tweet['created_at'],user,tweet['text']]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment