-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.py
More file actions
110 lines (83 loc) · 3.23 KB
/
display.py
File metadata and controls
110 lines (83 loc) · 3.23 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
99
100
101
102
103
104
105
106
107
108
109
# !/usr/bin/python3.5
import pymysql
db = pymysql.connect("localhost", "root", "password", "movie")
cursor = db.cursor()
def disp(table):
sql = "select * from " + table
if table == 'actor':
actor(sql)
elif table == 'director':
director(sql)
elif table == 'movies':
movies(sql)
elif table == 'movie_cast':
cast(sql)
elif table == 'rating':
rating(sql)
else:
print("Invalid Entry")
try:
def actor(sql):
cursor.execute(sql)
print("\n-----------------------------------")
print("| ACT_ID | ACT_NAME | SEX |")
print("-----------------------------------")
results = cursor.fetchall()
for row in results:
id = row[0]
name = row[1]
sex = row[2]
print("| " + str(id).ljust(5) + "| " + str(name).ljust(15) + " | " + str(sex).ljust(3) + "|")
print("-----------------------------------")
def director(sql):
cursor.execute(sql)
print("\n--------------------------------------------")
print("| DIR_ID | DIR_NAME | DIR_PHONE |")
print("--------------------------------------------")
results = cursor.fetchall()
for row in results:
id = row[0]
name = row[1]
phone = row[2]
print("| " + str(id).ljust(5) + "| " + str(name).ljust(20) + "| " + str(phone).ljust(10) + "|")
print("--------------------------------------------")
def movies(sql):
cursor.execute(sql)
print("\n----------------------------------------------------------------")
print("| MOV_ID | MOV_TITLE | MOV_YEAR | MOV_LANG | DIR_ID |")
print("----------------------------------------------------------------")
results = cursor.fetchall()
for row in results:
id = row[0]
name = row[1]
year = row[2]
lang = row[3]
d_id = row[4]
print("| " + str(id).ljust(5) + "| " + str(name).ljust(20) + "| " + str(year).ljust(7) + "| " + str(
lang).ljust(9) + "| " + str(d_id).ljust(5) + "|")
print("----------------------------------------------------------------")
def cast(sql):
cursor.execute(sql)
print("\n-----------------------------")
print("| ACT_ID | MOV_ID | ROLE |")
print("-----------------------------")
results = cursor.fetchall()
for row in results:
a_id = row[0]
m_id = row[1]
role = row[2]
print("| " + str(a_id).ljust(5) + "| " + str(m_id).ljust(5) + " | " + str(role).ljust(8) + "|")
print("-----------------------------")
def rating(sql):
cursor.execute(sql)
print("\n------------------")
print("| MOV_ID | STARS |")
print("------------------")
results = cursor.fetchall()
for row in results:
m_id = row[0]
star = row[1]
print("| " + str(m_id).ljust(5) + " | " + str(star).ljust(5) + "|")
print("------------------")
except:
print("Error: unable to fetch data")