Created
May 11, 2014 13:40
-
-
Save khris/ea27f1b47db6c5db3441 to your computer and use it in GitHub Desktop.
Simple Twitter bot
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
OAUTH_TOKEN = '<YOUR ACCESS TOKEN>' | |
OAUTH_SECRET = '<YOUR ACCESS TOKEN SECRET>' | |
CONSUMER_KEY = '<YOUR API KEY>' | |
CONSUMER_SECRET = '<YOUR API SECRET>' | |
# seconds | |
INTERVAL = 30 |
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
#! /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