server.py 1.22 KB
Newer Older
1
#!/bin/python
2
3
4
5
from flask import Flask, render_template, g
import mysql.connector
import config

6
7
app = Flask(__name__)

8
9
10
11
12
13
14
def query(operation, *params):
	if 'db' not in g or not g.db.is_connected():
		g.db = mysql.connector.connect(user=config.db_user, password=config.db_passwd, host=config.db_host, database=config.db_db)
	cur = g.db.cursor(dictionary=True)
	cur.execute(operation, params)
	return cur.fetchall()

15
16
@app.route('/')
def index():
17
	return render_template('index.html', latestvideos=query('''
18
				SELECT lectures.*, max(videos.time_updated) AS lastvidtime, courses.short, courses.downloadable, courses.title AS coursetitle
19
20
21
22
23
24
25
26
27
				FROM lectures
				LEFT JOIN videos ON (videos.lecture_id = lectures.id)
				LEFT JOIN courses on (courses.id = lectures.course_id)
				WHERE (videos.time_updated >= SUBDATE(NOW(), 14))
					AND (%s OR (courses.visible AND courses.listed AND lectures.visible AND videos.visible))
				GROUP BY videos.lecture_id
				ORDER BY lastvidtime DESC
				LIMIT 5
			''', False))
28

Andreas Valder's avatar
Andreas Valder committed
29
30
31
32
33
34
35
36
@app.route('/videos')
def videos():
	return render_template('videos.html', active_page='videos')

@app.route('/faq')
def faq():
	return render_template('faq.html',  active_page='faq')

37
38
39
if __name__ == '__main__':
	app.debug = True
	app.run()