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
#-----------------------------------------------------------------------------
# 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'
counts = {'lc': 0}
# Create the SQLite connection
conn = sqlite3.connect('/etc/pihole/pihole.db')
with conn:
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
c.execute('PRAGMA journal_mode=WAL;')
# Parse the log file.
for line in open(logfile):
line = line.rstrip()
counts['lc'] += 1
if (counts['lc'] % 10000) == 0:
conn.commit()
sql = "INSERT INTO gravity (domain) VALUES (?)"
c.execute(sql, (line,))
with open(logfile) as f:
for line in f:
sql = "INSERT INTO gravity (domain) VALUES (?)"
c.execute(sql, (line,))