-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservertest.py
More file actions
30 lines (24 loc) · 811 Bytes
/
servertest.py
File metadata and controls
30 lines (24 loc) · 811 Bytes
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
import http.server
import socketserver
import sqlite3
PORT = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), Handler) as httpd:
print("serving at port", PORT)
web = input("Please enter your shortened URL code: ")
ecoded_string = toBase10(short_url)
redirect_url = 'http://localhost:5000'
with sqlite3.connect('urls.db') as conn:
cursor = conn.cursor()
select_row = """
SELECT URL FROM WEB_URL
WHERE ID=%s
"""%(decoded_string)
result_cursor = cursor.execute(select_row)
try:
redirect_url = result_cursor.fetchone()[0]
print(redirect_url)
except Exception as e:
print(e)
httpd.serve_forever()
app =