-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.py
69 lines (64 loc) · 1.89 KB
/
util.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
67
68
69
import os.path
import globals
cache = {}
def get_name(username):
cur = globals.mysqld.cursor(buffered=True)
cur.execute("select * from users where username = %s;", (username,))
fetch = cur.fetchall()
if len(fetch) == 0:
return "Anonymous"
user = fetch[0]
return user[2] + " " + user[3];
def txt(fname="frame", **args):
filename = "frames/%s.html" % fname
if fname in cache:
mtime, txt = cache[fname]
if os.path.getmtime(filename) == mtime:
return txt % args
txt = open(filename).read()
cache[fname] = (os.path.getmtime(filename), txt)
return txt % args
def user_exists(username, cursor=None):
if cursor == None:
cursor = globals.mysqld.cursor()
cursor.execute("select * from users where username = %s;", (username,))
return len(cursor.fetchall()) > 0
def get_nav(session):
if 'username' in session:
name = get_name(session['username'])
print(name)
return txt("nav_login", realname = name)
else:
return txt("nav_logout")
def pool_label(pool):
params = globals.pool_params
pool_values ={}
for x in range(len(params)):
pool_values[params[x]] = pool[x]
return pool_values
def people_for_pool(pool_id):
cur = globals.mysqld.cursor(buffered=True)
cur.execute('select * from links where pool_id = %s', (pool_id,))
people_coming = "None"
people_list = cur.fetchall()
ret = []
for x in people_list:
ret = ret + [x[0]]
return ret
def get_pool_info(pool_id):
cur = globals.mysqld.cursor(buffered=True)
cur.execute("select * from carpools where pool_id = %s;", (pool_id,))
pools = cur.fetchall()
if len(pools) == 0:
return None
else:
pool = pool_label(pools[0])
people_list = people_for_pool(pool_id)
people_coming = "None"
for person in people_list:
if people_coming == "None":
people_coming = ""
people_coming = people_coming + "<li>%s</li>" % person
pool.update({'people_coming': people_coming})
pool['driver_name'] = get_name(pool['driver_id'])
return pool