This repository has been archived by the owner on Jul 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTDevil.py
46 lines (39 loc) · 1.45 KB
/
TDevil.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
from twython import Twython, TwythonError
import time
import sys
APP_KEY = 'YOUR KEY'
APP_SECRET = 'YOUR SECRET'
OAUTH_TOKEN = 'YOUR TOKEN'
OAUTH_TOKEN_SECRET = 'YOUR SECRET TOKEN'
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
def countdown(t): # in seconds
for i in range(t,0,-1):
print "Tweeting again in %d seconds\r" % i,
sys.stdout.flush()
time.sleep(1)
try:
with open('liners.txt', 'r+') as tweetfile:
buff = tweetfile.readlines()
for line in buff[:]:
line = line.strip(r'\n') #Strips any empty line.
if len(line)<=140 and len(line)>0:
print "Tweeting..."
twitter.update_status(status=line)
with open ('liners_tweeted_and_skipped.txt', 'a') as file:
file.writelines(line) #Adds the line that has been tweeted.
with open ('liners.txt', 'w') as tweetfile:
buff.remove(line) #Removes the tweeted line from buffer.
tweetfile.writelines(buff) #Writes buff to lines.txt.
countdown(450)
print
else:
with open ('liners_tweeted_and_skipped.txt', 'a') as file:
file.writelines(line) #Adds the line that has been skipped.
with open ('liners.txt', 'w') as tweetfile:
buff.remove(line) #Removes the line that has more than 140 characters.
tweetfile.writelines(buff) #Writes buff to lines.txt.
print "Skipped line - Char length violation"
continue
print "No more lines to tweet..." #When you see this... Well, Go find some new tweets...
except TwythonError as e:
print e