-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoal-perhaps.py
32 lines (25 loc) · 910 Bytes
/
coal-perhaps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/env python
# Public domain; MZMcBride; 2012
import random
from twitter.api import Twitter
from twitter.oauth import OAuth, read_token_file
import settings
f = open(settings.initial_path + 'coal-wisdom.txt', 'r')
wisdom = f.read().strip('\n').split('\n')
f.close()
oauth_filename = settings.initial_path + 'coal-oauth'
oauth_token, oauth_token_secret = read_token_file(oauth_filename)
poster = Twitter(auth=OAuth(oauth_token,
oauth_token_secret,
settings.consumer_key,
settings.consumer_secret),
secure=True,
api_version='1.1',
domain='api.twitter.com')
# Twitter blocks duplicate posts, so try up to ten times.
for i in range(10):
try:
poster.statuses.update(status=random.choice(wisdom))
break
except: # Unnamed!
continue