-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_geo.py
83 lines (58 loc) · 1.65 KB
/
admin_geo.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
70
71
72
73
74
75
76
77
78
79
80
81
82
import psycopg2
from psycopg2.extras import RealDictCursor
def get_admin_geofinder_header(db):
conn = psycopg2.connect(db)
cursor = conn.cursor(cursor_factory=RealDictCursor)
# Set query
query = """
SELECT
SUM(CASE WHEN loc_playable = FALSE THEN 1 ELSE 0 END) AS loc_playable,
SUM(CASE WHEN loc_url_valid = FALSE THEN 1 ELSE 0 END) AS loc_url_valid,
SUM(CASE WHEN loc_image_valid = FALSE THEN 1 ELSE 0 END) AS loc_image_valid,
SUM(CASE WHEN loc_key_shp_valid = FALSE THEN 1 ELSE 0 END) AS loc_key_shp_valid
FROM locations;
"""
# Run query
cursor.execute(query, (id,))
# Get results
results = cursor.fetchone()
cursor.close()
conn.close()
return(results)
def get_admin_geofinder_content(db):
conn = psycopg2.connect(db)
cursor = conn.cursor(cursor_factory=RealDictCursor)
# Set query
query = """
SELECT
g.*,
l.*
FROM geofinder AS g
JOIN locations AS l ON g.geofinder_locations_id = l.id
ORDER BY g.geofinder_date
;
"""
# Run query
cursor.execute(query)
# Get results
results = cursor.fetchall()
cursor.close()
conn.close()
return results
def get_admin_geofinder_loc(db, id):
conn = psycopg2.connect(db)
cursor = conn.cursor(cursor_factory=RealDictCursor)
# Set query
query = """
SELECT *
FROM locations
WHERE id = %s
;
"""
# Run query
cursor.execute(query, (id,))
# Get results
results = cursor.fetchone()
cursor.close()
conn.close()
return(results) #81