This repository was archived by the owner on Dec 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathapp.py
More file actions
78 lines (62 loc) · 1.86 KB
/
app.py
File metadata and controls
78 lines (62 loc) · 1.86 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
import string
import random
import time
from datetime import datetime
from flask import Flask, g
from functools import wraps
app = Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
def get_db():
db = getattr(g, '_database', None)
if db is None:
db = g._database = sqlite3.connect('db/watchparty.sqlite3')
db.row_factory = sqlite3.Row
setattr(g, '_database', db)
return db
@app.teardown_appcontext
def close_connection(exception):
db = getattr(g, '_database', None)
if db is not None:
db.close()
def query_db(query, args=(), one=False):
db = get_db()
cursor = db.execute(query, args)
rows = cursor.fetchall()
db.commit()
cursor.close()
if rows:
if one:
return rows[0]
return rows
return None
def new_user():
name = "Unnamed User #" + ''.join(random.choices(string.digits, k=6))
password = ''.join(random.choices(string.ascii_lowercase + string.digits, k=10))
api_key = ''.join(random.choices(string.ascii_lowercase + string.digits, k=40))
u = query_db('insert into users (name, password, api_key) ' +
'values (?, ?, ?) returning id, name, password, api_key',
(name, password, api_key),
one=True)
return u
# TODO: If your app sends users to any other routes, include them here.
# (This should not be necessary).
@app.route('/')
@app.route('/profile')
@app.route('/login')
@app.route('/room')
@app.route('/room/<chat_id>')
def index(chat_id=None):
# time.sleep(4)
return app.send_static_file('index.html')
@app.errorhandler(404)
def page_not_found(e):
return app.send_static_file('404.html'), 404
# -------------------------------- API ROUTES ----------------------------------
# TODO: Create the API
# @app.route('/api/signup')
# def login():
# ...
# @app.route('/api/login')
# def login():
# ...
# ... etc