-
Notifications
You must be signed in to change notification settings - Fork 0
/
reverseupdate.py
executable file
·60 lines (53 loc) · 1.97 KB
/
reverseupdate.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
#!/usr/bin/python
from twitter import *
import psycopg2
conn = psycopg2.connect(database = "aws", user = "milanmenezes", password = "nightfury", host = "milan-aws.crbk9i7trzoq.ap-south-1.rds.amazonaws.com", port = "5432")
api = Api(consumer_key='QBSJiqeISh3g98v4En482W0rU',
consumer_secret='x8Wgr1RIF5b6sR14wkuNIZvNOTslCBkrRKUBLCSCBT6Od0oM0S',
access_token_key='518104135-N40eShH1AonSJ4Ca0STFbw8ht9VbyCSoeHw8tJig',
access_token_secret='gvJewbmkt3PhNg24WU6ITitsAyMVHex3VgcWYV4BJbTWr')
q="q=%23VIVOIPL&result_type=recent&since=2018-01-01&count=100"
try:
c = conn.cursor()
c.execute("Select min(ID) from DATASTORE;")
tid=c.fetchone()[0]-1
c.close()
res = api.GetSearch(raw_query=q+"&max_id="+str(tid), return_json=True)
temp=res["statuses"]
i=0
tid=0
while(i<150):
print "Call no:",i
i+=1
c = conn.cursor()
for t in temp:
media=False
tid=t["id"]
userid=t["user"]["id"]
username=t["user"]["screen_name"].replace("'","''")
if "extended_entities" in t:
if "media" in t["extended_entities"]:
if t["extended_entities"]["media"]:
media=True
text=t["text"].replace("'","''")
created=t["created_at"]
retweet=t["retweet_count"]
fav=t["favorite_count"]
loc=t["user"]["location"].replace("'","''")
# c.execute("Insert into DATASTORE values (?,?,?,?,?,?,?,?);",(tid, userid, username, media, text, retweet, fav, loc,))
c.execute("Insert into DATASTORE values ("+str(tid)+", "+str(userid)+", '"+username.encode("utf-8")+"', "+str(media)+", '"+text.encode("utf-8")+"', "+str(retweet)+", "+str(fav)+", '"+loc.encode("utf-8")+"', TIMESTAMP '"+created.encode("utf-8")+"' );")
conn.commit()
# c = conn.cursor()
c.execute("Select min(ID) from DATASTORE;")
tid=c.fetchone()[0]-1
c.close()
res = api.GetSearch(raw_query=q+"&max_id="+str(tid), return_json=True)
print tid
temp=res["statuses"]
if not temp:
break
except:
print "Error"
finally:
conn.close()
print "Successfull"