This repository was archived by the owner on Jan 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrikersbot.py
More file actions
executable file
·67 lines (56 loc) · 2 KB
/
rikersbot.py
File metadata and controls
executable file
·67 lines (56 loc) · 2 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import csv
import datetime
import tweepy
import random
# cron settings
# 31 6 * * * python /home/denten/rikersbot/rikersbot.py
# paths have to be explicit for cron
path = '/home/denten/rikersbot/'
# separate the credits out to keep out of github
def creds():
with open(path + 'keys.csv', 'r') as csvfile:
creds = csv.DictReader(csvfile, delimiter=",")
row = creds.next()
return row['consumer_key'], row['consumer_secret'], row['access_token'], row['access_token_secret']
# select line number at random, check against what has been twitted
def text():
# read in the forbidden list and cast to int
with open(path + 'forbidden.txt', 'r') as f:
flist = f.readlines()
forbid_list = [int(i) for i in flist]
# open tweets get length
with open(path + 'tweets.txt', 'r') as f:
tweets_list = f.readlines()
tweets_range = len(tweets_list) - 1
# generate a random number in range
tweet_index = random.randint(0,tweets_range)
# roll until we get a good number
while tweet_index in forbid_list:
tweet_index = random.randint(0,tweets_range)
else:
# append to the forbidden list and return the tweet
with open(path + 'forbidden.txt', 'a') as f:
f.write(str(tweet_index) + '\n')
return tweets_list[tweet_index]
def tweet(k, t):
try:
# shake hands and update status
auth = tweepy.OAuthHandler(k[0], k[1])
auth.set_access_token(k[2], k[3])
api = tweepy.API(auth)
api.update_status(status=t)
# debug stuff
# print "akey = " + k[2]
# print "asecret = " + k[3]
# print "token = " + k[0]
# print "secret = " + k[1]
# dummy write to a file instead of tweeting
# f = open(path + 'log.txt', 'a')
# f.write(t + '\n')
except tweepy.error.TweepError, e:
# consider logging errors to file
print e.message[0]['code']
print e.args[0][0]['code']
pass
# logic
tweet(creds(), text())