krz/omaha-metro-blotter

Archive of police activity and ALPR surveillance across the Omaha metro. alpr archive omaha police surveillance

Commit 1627615c29

1627615c291024f159f6699768fbc13662e83bbd

parent: 826a705dfa

Verified · cmc

cmc <hello@cleberg.net> · 2024-01-24 19:36 UTC

update path and add method to delete extra header rows

Layout: unified · split

ingest.py +7 −3
@@ -4,7 +4,7 @@ import sqlite3
4import os 4import os
5 5
6# Create the database file 6# Create the database file
7connection = sqlite3.connect('./raw_data/ingress.db') 7connection = sqlite3.connect('./raw_data/test.db')
8 8
9# Creating a cursor object to execute SQL queries 9# Creating a cursor object to execute SQL queries
10cursor = connection.cursor() 10cursor = connection.cursor()
@@ -34,14 +34,14 @@ create_table = '''CREATE TABLE incidents(
34cursor.execute(create_table) 34cursor.execute(create_table)
35 35
36# Point to the data directory 36# Point to the data directory
37directory = os.fsencode("../raw_data/") 37directory = os.fsencode("./raw_data/")
38 38
39# Loop through all raw data files 39# Loop through all raw data files
40for file in os.listdir(directory): 40for file in os.listdir(directory):
41 filename = os.fsdecode(file) 41 filename = os.fsdecode(file)
42 if filename.endswith(".csv"): 42 if filename.endswith(".csv"):
43 # Opening the file 43 # Opening the file
44 file = open("../raw_data/" + filename) 44 file = open("./raw_data/" + filename)
45 45
46 # Reading the contents of the file 46 # Reading the contents of the file
47 contents = csv.reader(file) 47 contents = csv.reader(file)
@@ -58,6 +58,10 @@ for file in os.listdir(directory):
58 else: 58 else:
59 continue 59 continue
60 60
61# Delete extra copies of the header row that were inserted
62delete_headers = "DELETE FROM incidents WHERE rb = 'RB Number'"
63cursor.execute(delete_headers)
64
61# Test query to see if the data loaded 65# Test query to see if the data loaded
62select_all = "SELECT * FROM incidents" 66select_all = "SELECT * FROM incidents"
63rows = cursor.execute(select_all).fetchall() 67rows = cursor.execute(select_all).fetchall()