Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@khris
Created May 11, 2014 13:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khris/ea27f1b47db6c5db3441 to your computer and use it in GitHub Desktop.
Save khris/ea27f1b47db6c5db3441 to your computer and use it in GitHub Desktop.
Simple Twitter bot
OAUTH_TOKEN = '<YOUR ACCESS TOKEN>'
OAUTH_SECRET = '<YOUR ACCESS TOKEN SECRET>'
CONSUMER_KEY = '<YOUR API KEY>'
CONSUMER_SECRET = '<YOUR API SECRET>'
# seconds
INTERVAL = 30
#! /usr/bin/env python
# coding: utf-8
from conf import *
import asyncio
import random
import fileinput
from twitter import *
@asyncio.coroutine
def tweet():
t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET))
reserved_tweets = []
random.seed()
with fileinput.input(files=('data.txt',)) as f:
for line in f:
reserved_tweets.append(line.split('\n')[0])
random.shuffle(reserved_tweets)
print(reserved_tweets)
while True:
for line in reserved_tweets:
t.statuses.update(status=line)
yield from asyncio.sleep(INTERVAL)
random.shuffle(reserved_tweets)
loop = asyncio.get_event_loop()
asyncio.async(tweet())
loop.run_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment