-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet_backup.py
61 lines (43 loc) · 1.25 KB
/
tweet_backup.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
#!/bin/python
import sys
import os
import commands
##########
#Program takes only one argument
#1st argument - twitter handle
##########
def clean_tweets(tweets):
tweet_file = open(tweets, 'r')
dirty = tweet_file.read()
tweet_file.close()
occur = dirty.count('<title>')
clean = "Tweets:" + '<br>'
index = dirty.find('<title>') + 7
endex = dirty.find('</title>')
while occur > 0:
index = dirty.find('<title>',index) + 7
endex = dirty.find('</title>',index)
temp = dirty[index:endex]
clean = clean + temp + '<br>'
occur = occur - 1
save = open(tweets,'w')
save.write(clean)
save.close()
def backup():
user = sys.argv[1]
store = user + '_tweets.html'
command = "curl -s --user-agent 'Mozilla' --insecure 'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name="
count = "&count=100"
page = "&page="
x = 1
print "This may take a while..."
tweet_file = open(store, 'w')
while x < 32:
tweets = commands.getoutput(command+user+count+page+str(x) + "'")
tweet_file.write(tweets)
x = x + 1
tweet_file.close()
print "Cleaning tweets"
clean_tweets(store)
if __name__ == '__main__':
backup()