-
Notifications
You must be signed in to change notification settings - Fork 0
/
toprank
71 lines (61 loc) · 2.06 KB
/
toprank
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
#!/usr/bin/python3
import sqlite3,sys
if len(sys.argv) != 4 and len(sys.argv) != 5 :
print("Usage:",sys.argv[0],"\"genres\" K StartYear EndYear")
sys.exit(1)
con = sqlite3.connect('a2.db')
cur = con.cursor()
genres = ""
n_args = len(sys.argv)
k = int(sys.argv[n_args-3])
start_year = sys.argv[n_args-2]
end_year = sys.argv[n_args-1]
if n_args == 5:
inp_genres = set((sys.argv[1]).split('&'))
#inp_genres = str(inp_genres)
#print (genres)
cur.execute('SELECT m.title, m.year, m.content_rating, m.lang, r.imdb_score, r.num_voted_users, '
'GROUP_CONCAT (g.genre) '
'FROM movie m '
'JOIN genre g ON (g.movie_id = m.id) '
'JOIN rating r ON (r.movie_id = m.id) '
"WHERE m.year >= {} AND m.year <= {} "
'GROUP BY m.title '
'ORDER BY r.imdb_score DESC, r.num_voted_users DESC'.format(start_year,end_year))
#SELECT m.title, GROUP_CONCAT (g.genre) AS gengen FROM movie m JOIN genre g ON (g.movie_id = m.id) JOIN rating r ON (r.movie_id = m.id) WHERE m.year >= 2000 AND m.year <= 2000 AND gengen IN ('Action') GROUP BY m.title ORDER BY r.imdb_score DESC;
i = 1
while i<=k:
t = cur.fetchone()
if t == None:
break
a,b,c,d,e,f,g = t
# rating should be float so 7 = 7.0
e = float(e)
if b == None:
continue
sql_genres = set(g.split(','))
if (inp_genres.issubset(sql_genres)):
if c == None:
print('{}. {} ({}, {}) [{}, {}]'.format(i,a,b,d,e,f))
else:
print('{}. {} ({}, {}, {}) [{}, {}]'.format(i,a,b,c,d,e,f))
i+=1
elif n_args == 4:
cur.execute('SELECT m.title, m.year, m.content_rating, m.lang, r.imdb_score, r.num_voted_users '
'FROM movie m '
'JOIN rating r ON (r.movie_id = m.id) '
"WHERE m.year >= {} AND m.year <= {} "
'ORDER BY r.imdb_score DESC, r.num_voted_users DESC'.format(start_year,end_year))
i = 1
while i<=k:
t = cur.fetchone()
if t == None:
break
a,b,c,d,e,f = t
# rating should be float so 7 = 7.0
e = float(e)
if b == None:
continue
print('{}. {} ({}, {}, {}) [{}, {}]'.format(i,a,b,c,d,e,f))
i+=1
con.close()