-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackend.py
More file actions
42 lines (31 loc) · 899 Bytes
/
backend.py
File metadata and controls
42 lines (31 loc) · 899 Bytes
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
"""Backend for boilerplate sql queries using psycopg2
"""
import psycopg2
conn = psycopg2.connect(dbname='Open_Policing')
cur = conn.cursor()
"""
id,
stop_date,
stop_time, location_raw,
county_name, county_fips,
driver_gender, driver_age,
driver_race, violation,
search_conducted, search_type,
stop_outcome, is_arrested,
officer_id, officer_gender,
officer_age, officer_race,
officer_rank,
out_of_state
"""
query_by_county = ''
query_whole_state = ''
# Do a loop to append user specs to queries
for specs in user_specs:
query_by_county += query_by_county + specs
# query_whole_state should be the same query without the GROUP BY
query_whole_state = query_by_county
query_by_county = query_by_county + ' GROUP BY county_name ORDER BY county_name;'
query_whole_state = query_whole_state + ';'
cur.execute(query_by_county)
counties_counts = cur.fetchall()
cur.execute(query_whole_state)