Created
February 8, 2018 12:21
-
-
Save impshum/82b34be0d06c180aaea6e2bf600cbd96 to your computer and use it in GitHub Desktop.
Tweepy Loops
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
consumer_key = 'XXXX' | |
consumer_secret = 'XXXX' | |
access_key = 'XXXX-XXXX' | |
access_secret = 'XXXX' | |
timer = 30 | |
message = 'It works!' | |
picture = 'path/to/picture.jpg' | |
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 time | |
import tweepy | |
import random | |
from config import * | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_key, access_secret) | |
api = tweepy.API(auth) | |
def tweet(message): | |
try: | |
api.update_status(message) | |
except tweepy.TweepError as e: | |
print(e) | |
time.sleep(5) | |
while True: | |
try: | |
print('Tweeting:', message) | |
tweet(message) | |
print('Sleeping for {} seconds'.format(timer)) | |
time.sleep(timer) | |
except KeyboardInterrupt: | |
print('\nExiting\n') | |
break |
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 time | |
import tweepy | |
import random | |
from config import * | |
script_dir = os.path.dirname(__file__) | |
picture_path = os.path.join(script_dir, picture) | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_key, access_secret) | |
api = tweepy.API(auth) | |
def tweet(message): | |
try: | |
api.update_with_media(picture_path, message) | |
except tweepy.TweepError as e: | |
print(e) | |
time.sleep(5) | |
while True: | |
try: | |
print('Tweeting:', message) | |
tweet(message) | |
print('Sleeping for {} seconds'.format(timer)) | |
time.sleep(timer) | |
except KeyboardInterrupt: | |
print('\nExiting\n') | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment