-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathid_pagination.py
More file actions
41 lines (33 loc) · 1.21 KB
/
id_pagination.py
File metadata and controls
41 lines (33 loc) · 1.21 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
import psycopg2
import time
try:
connection = psycopg2.connect(user = "Abdi",
password = "",
host = "localhost",
port = "5432",
database = "twitter")
cursor = connection.cursor()
cursor.execute("SELECT * from tweet ORDER BY id DESC LIMIT 101")
tweets = cursor.fetchall()
page_size = 100
next_page_id = tweets[-1][0]
s_total = time.time()
for i in range(20000):
start = time.time()
# print("page %s" % i)
cursor.execute("SELECT * from tweet WHERE id <= %s ORDER BY id DESC LIMIT 101", (next_page_id,))
tweets = cursor.fetchall()
next_page_id = tweets[-1][0]
end = time.time()
if i % 100 == 0:
print("%s,%s" % (i, end - start))
e_total = time.time()
print("TOTAL %s" % (e_total - s_total))
except (Exception, psycopg2.Error) as error :
print ("Error while connecting to PostgreSQL", error)
finally:
#closing database connection.
if(connection):
cursor.close()
connection.close()
# print("PostgreSQL connection is closed")