-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_test.py
More file actions
98 lines (75 loc) · 1.76 KB
/
db_test.py
File metadata and controls
98 lines (75 loc) · 1.76 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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#db_test.py
import sqlite3
conn = sqlite3.connect("tweets.db")
cur = conn.cursor()
points = 0
# Task 1
# at least 300 tweets?
try:
q = 'SELECT COUNT(*) FROM Tweets WHERE author_id=18033550' # umsi account id
r = cur.execute(q)
v = r.fetchone()[0]
if v > 300:
points += 5
except:
pass
# no tweets before Sept 1, 2016?
try:
q = 'SELECT COUNT(*) FROM Tweets WHERE time_stamp > "2016-09-01 00:00"'
r = cur.execute(q)
v = r.fetchone()[0]
q = 'SELECT COUNT(*) FROM Tweets WHERE time_stamp <= "2016-09-01 00:00"'
r = cur.execute(q)
v2 = r.fetchone()[0]
if v > 0 and v2 == 0:
points += 5
except:
pass
# contains exactly one copy of an arbitrary tweet from Nov 30
try:
q = 'SELECT COUNT(*) FROM Tweets WHERE tweet_id=804011935658287105'
r = cur.execute(q)
v = r.fetchone()[0]
if v == 1:
points += 5
except:
pass
print('Task 1 points:', points)
# Task 2
points = 0
# can link from a tweet to its author
try:
q = 'SELECT username FROM Authors JOIN Tweets '
q += 'ON Tweets.author_id=Authors.author_id WHERE tweet_id=827203934905364480'
r = cur.execute(q)
v = r.fetchone()[0]
if v == 'umsi':
points += 5
except:
pass
# can look up a mentioned authors for a tweet
try:
q = 'SELECT COUNT(*) FROM Authors '
q += 'JOIN Mentions ON Authors.author_id = Mentions.author_id '
q += 'JOIN Tweets ON Mentions.tweet_id = Tweets.tweet_id '
q += 'WHERE Tweets.tweet_id = 805816623810703360' # aadl
r = cur.execute(q)
v = r.fetchone()[0]
if v == 4:
points += 5
except:
pass
# verify no duplicate authors
try:
q = 'SELECT COUNT(*) FROM Authors'
r = cur.execute(q)
v = r.fetchone()[0]
q = 'SELECT COUNT(DISTINCT author_id) FROM Authors'
r = cur.execute(q)
v2 = r.fetchone()[0]
if v == v2:
points += 5
except:
pass
print('Task 2 points:', points)
conn.close()