Commits squashed, lots of changes.

This commit is contained in:
Dan Schaper 2016-10-01 21:13:55 -07:00
parent 2e331cbd73
commit e6873e0ebd

View file

@ -43,50 +43,29 @@
import sqlite3 import sqlite3
#-----------------------------------------------------------------------------
# Functions
#-----------------------------------------------------------------------------
def create_tables():
qt = 'DROP TABLE IF EXISTS gravity'
c.execute(qt)
conn.commit()
qt = '''
CREATE TABLE IF NOT EXISTS gravity (
idx integer primary key autoincrement,
domain text
)
'''
c.execute(qt)
conn.commit()
#-----------------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------------
logfile = '/etc/pihole/pihole.2.eventHorizon.txt' logfile = '/etc/pihole/pihole.2.eventHorizon.txt'
counts = {'lc': 0}
# Create the SQLite connection # Create the SQLite connection
conn = sqlite3.connect('/etc/pihole/pihole.db') conn = sqlite3.connect('/etc/pihole/pihole.db')
with conn: with conn:
c = conn.cursor() c = conn.cursor()
create_tables() c.execute('DROP TABLE IF EXISTS gravity')
qt = '''
CREATE TABLE IF NOT EXISTS gravity (
idx INTEGER PRIMARY KEY ASC,
domain text
)
'''
c.execute(qt)
# enable WAL mode # enable WAL mode
c.execute('PRAGMA journal_mode=WAL;') c.execute('PRAGMA journal_mode=WAL;')
# Parse the log file. # Parse the log file.
for line in open(logfile): with open(logfile) as f:
line = line.rstrip() for line in f:
counts['lc'] += 1 sql = "INSERT INTO gravity (domain) VALUES (?)"
c.execute(sql, (line,))
if (counts['lc'] % 10000) == 0:
conn.commit()
sql = "INSERT INTO gravity (domain) VALUES (?)"
c.execute(sql, (line,))