-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtb.py
66 lines (51 loc) · 1.87 KB
/
tb.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
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import tweepy, time, sys, random, json, re, datetime
random.seed()
def parseIn():
i = 0
blackcards = []
f = open('blackcards.txt', 'r')
line = f.readline() #Read a line from the file
while (line != ''):
line = re.sub('\s+',' ',line)
blackcards.append(line) #Store the word
i = i + 1
line = f.readline() #Read a new line
i = 0
whitecards = []
f = open('whitecards.txt', 'r')
line = f.readline() #Read a line from the file
while (line != ''):
line = re.sub('\s+',' ',line)
whitecards.append(line) #Store the word
i = i + 1
line = f.readline() #Read a new line
return blackcards, whitecards
#end parseIn
def newtweet():
blackcards, whitecards = parseIn()
blackcardsN = random.randint(0, blackcards.__len__())
whitecardsN = random.randint(0, whitecards.__len__())
tweet = blackcards[blackcardsN]
tweet = tweet.replace('__________', " " + whitecards[whitecardsN] + " ")
tweet = re.sub('\s+',' ',tweet) #Removes all whitespaces and replaces them with spaces
return tweet
#enter the corresponding information from your Twitter application:
CONSUMER_KEY = ''#keep the quotes, replace this with your consumer key
CONSUMER_SECRET = ''#keep the quotes, replace this with your consumer secret key
ACCESS_KEY = ''#keep the quotes, replace this with your access token
ACCESS_SECRET = ''#keep the quotes, replace this with your access token secret
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
while(True):
text=newtweet(1)
if(len(text)<140):
print "Generating...\n"
text=newtweet()
print text
print "\nTweeting..."
api.update_status(status=text)
print "Tweeted!"
time.sleep(1800)#Tweet every 30 minutes