-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchinook_sql.py
executable file
·66 lines (53 loc) · 1.56 KB
/
chinook_sql.py
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
from datetime import datetime
import sqlite3
def sql_read_app(environ, start_response):
status = '200 OK' # HTTP Status
headers = [('Content-type', 'text/html; charset=utf-8')] # HTTP Headers
start_response(status, headers)
#mydtetme = datetime.now().ctime()
#content='''<p>The time is now {} Surprise!'''.format(mydtetme)
conn = sqlite3.connect("/Users/patrickpiwowarczyk/Documents/Dropbox/Depaul/School/DePaul/Web Dev 1 IT231/Lab 4 Python and Databases - SQLite attached files Oct 9, 2018 128 AM/chinook.db")
conn.text_factory = str
cur = conn.cursor()
cur.execute("SELECT * FROM tracks")
rows = cur.fetchall()
rout=('''<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
margin: auto;
table-layout:auto;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<table>
<caption><h2>Music Tracks</h2></caption>
<tr>
<th>ID</th>
<th>Track Name</th>
</tr>''')
for row in rows:
# rowout='''<p>row {} name {}</p><br />'''.format(row[0],row[1])
rowout='''<tr><td> {} </td><td> {} </td></tr>'''.format(row[0],row[1])
rout = rout + rowout
# rout.append(bytes(row,'UTF-8') )
htmlclose=('''</table>
</body>
</html>''')
rout = rout + htmlclose
# print(rout)
# The returned object is going to be printed
# return [b"Hello World"]
return[bytes(rout, 'UTF-8')]