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
44import os
55
66# Create the database file
7connection = sqlite3.connect('./raw_data/ingress.db')
7connection = sqlite3.connect('./raw_data/test.db')
88
99# Creating a cursor object to execute SQL queries
1010cursor = connection.cursor()
@@ -34,14 +34,14 @@ create_table = '''CREATE TABLE incidents(
3434cursor.execute(create_table)
3535
3636# Point to the data directory
37directory = os.fsencode("../raw_data/")
37directory = os.fsencode("./raw_data/")
3838
3939# Loop through all raw data files
4040for file in os.listdir(directory):
4141 filename = os.fsdecode(file)
4242 if filename.endswith(".csv"):
4343 # Opening the file
44 file = open("../raw_data/" + filename)
44 file = open("./raw_data/" + filename)
4545
4646 # Reading the contents of the file
4747 contents = csv.reader(file)
@@ -58,6 +58,10 @@ for file in os.listdir(directory):
5858 else:
5959 continue
6060
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
6165# Test query to see if the data loaded
6266select_all = "SELECT * FROM incidents"
6367rows = cursor.execute(select_all).fetchall()