Created
September 25, 2017 03:32
-
-
Save beefy/2e4139cef4de82fdbd006c9d222bd648 to your computer and use it in GitHub Desktop.
a twitter bot to tweet tweets from a text file
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
import tweepy | |
import time | |
def login_to_twitter(consumer_key, consumer_secret, access_token, access_token_secret): | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_token, access_token_secret) | |
return tweepy.API(auth) | |
def tweet(api, tweet): | |
if len(tweet) > 0: | |
print u"tweeting: {}".format(tweet) | |
api.update_status(tweet) | |
def post_tweets(): | |
with open("msg.txt", "r") as f: | |
text = f.read() | |
api = login_to_twitter(*([line.strip() for line in open("mycreds.txt", "r")])) | |
for i in xrange(0, len(text), 140): | |
tweet(api, text[i:i+140]) | |
if __name__ == '__main__': | |
post_tweets() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment