Skip to content

Instantly share code, notes, and snippets.

@amar061996
Last active March 27, 2017 07:19
Show Gist options
  • Select an option

  • Save amar061996/9c4d3d3eb56cc2819a07 to your computer and use it in GitHub Desktop.

Select an option

Save amar061996/9c4d3d3eb56cc2819a07 to your computer and use it in GitHub Desktop.
read tweets from your timeline,check names of followers,read tweets posted by you and post tweets to your timeline 'num' times every 'min' mins
import tweepy,time,sys
from tweepy import OAuthHandler
import json
import io
fw=io.open("twitter.txt",'w',encoding='utf8')
def process_or_store(tweet):
print json.dumps(tweet) #use tweet['text'] to print only the text part
def read_tweets():
consumer_key='Your Consumer Key'
consumer_secret='Your Consumer Secret'
access_token='Your Access Token'
access_secret='Your Access Secret'
auth=OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_secret)
api=tweepy.API(auth)
for status in tweepy.Cursor(api.home_timeline).items(10): #to read tweets from timeline
fw.write(status.text+"\n")
process_or_store(status._json)
"""for friend in tweepy.Cursor(api.friends).items(): #to get the list of followers
fw.write(friend.name+"\n")
process_or_store(friend._json)"""
"""for tweet in tweepy.Cursor(api.user_timeline).items(10): #to get our tweets
process_or_store(tweet._json)"""
fw.close() #use when using first function to write timeline tweets
def post_tweet(tweet,num,min): #function to tweet on twitter
consumer_key='Your Consumer Key'
consumer_secret='Your Consumer Secret'
access_token='Your Access Token'
access_secret='Your Access Secret'
auth=OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token,access_secret)
api=tweepy.API(auth)
i=0
while i<num:
api.update_status(status=tweet)
time.sleep(min*60) #tweet 10 times after every 10 mins
read_tweets() #calling function to read tweets from your timeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment