-
Notifications
You must be signed in to change notification settings - Fork 0
/
acting
60 lines (51 loc) · 1.28 KB
/
acting
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/python3
import sqlite3,sys
if len(sys.argv) != 2 :
print("Usage:",sys.argv[0],"\"actor's name\"")
sys.exit(1)
actor = sys.argv[1]
con = sqlite3.connect('a2.db')
cur = con.cursor()
cur.execute('SELECT m.title, d.name, m.year, m.content_rating, r.imdb_score '
'FROM movie m '
'JOIN acting ac ON (m.id = ac.movie_id) '
'JOIN actor a ON (a.id = ac.actor_id) '
'LEFT JOIN director d ON (d.id = m.director_id) '
'JOIN rating r ON (r.movie_id = m.id) '
"WHERE a.name = '%s' COLLATE NOCASE "
'ORDER BY m.year, m.title ASC'%actor)
i = 1
end = []
while True:
t = cur.fetchone()
if t == None:
break
a,b,c,d,e = t
# rating should be float so 7 = 7.0
e = float(e)
# year is None then print in the end
if c == None:
end.append(t)
continue
#no director
if b == None:
a = a.strip()
print('{}. {} -- ({}, {}, {})'.format(i,a,c,d,e))
else:
print('{}. {} -- {} ({}, {}, {})'.format(i,a,b,c,d,e))
i+=1
for j in range(0, len(end)):
t = end[j]
if t == None:
break
a,b,c,d,e = t
# rating should be float so 7 = 7.0
e = float(e)
a = a.strip()
if b == None:
a = a.strip()
print('{}. {} -- ({}, {})'.format(i,a,d,e))
else:
print('{}. {} -- {} ({}, {})'.format(i,a,b,d,e))
i+=1
con.close()