Skip to content

Instantly share code, notes, and snippets.

@impshum
Created February 8, 2018 12:21
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 impshum/82b34be0d06c180aaea6e2bf600cbd96 to your computer and use it in GitHub Desktop.
Save impshum/82b34be0d06c180aaea6e2bf600cbd96 to your computer and use it in GitHub Desktop.
Tweepy Loops
consumer_key = 'XXXX'
consumer_secret = 'XXXX'
access_key = 'XXXX-XXXX'
access_secret = 'XXXX'
timer = 30
message = 'It works!'
picture = 'path/to/picture.jpg'
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
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