-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_main.py
63 lines (46 loc) · 1.53 KB
/
admin_main.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
import psycopg2
from psycopg2.extras import RealDictCursor
def get_admin_main_header(db):
conn = psycopg2.connect(db)
cursor = conn.cursor(cursor_factory=RealDictCursor)
# Set query
query = """
SELECT
(SELECT CURRENT_TIMESTAMP::date) AS admin_main_header_today,
(SELECT SUM(CASE WHEN loc_playable = FALSE THEN 1 ELSE 0 END) FROM locations WHERE loc_game = 'geofinder') AS admin_main_header_geofinder,
(SELECT SUM(CASE WHEN loc_playable = FALSE THEN 1 ELSE 0 END) FROM locations WHERE loc_game = 'geo50x') AS admin_main_header_fifty,
(SELECT SUM(CASE WHEN loc_playable = FALSE THEN 1 ELSE 0 END) FROM locations) AS admin_main_header_locations
;
"""
# Run query
cursor.execute(query, (id,))
# Get results
results = cursor.fetchone()
cursor.close()
conn.close()
return results
def get_admin_main_content(db):
conn = psycopg2.connect(db)
cursor = conn.cursor(cursor_factory=RealDictCursor)
# Set query
query = """
SELECT
g.*,
l.id,
l.loc_playable,
l.loc_city,
l.loc_state,
l.loc_country
FROM geofinder AS g
JOIN locations AS l ON g.geofinder_locations_id = l.id
WHERE geofinder_date >= CURRENT_TIMESTAMP::date
ORDER BY g.geofinder_date
;
"""
# Run query
cursor.execute(query)
# Get results
results = cursor.fetchall()
cursor.close()
conn.close()
return results