From 14424939a9e106778b5bbce051c821d80544323e Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sun, 2 Oct 2016 11:26:40 -0700 Subject: [PATCH] Set correct db in gravity_parse. Start using `with` in dnsmasq --- advanced/Scripts/dnsmasq_parse.py | 25 +++++++++++++------------ advanced/Scripts/gravity_parse.py | 2 +- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/advanced/Scripts/dnsmasq_parse.py b/advanced/Scripts/dnsmasq_parse.py index 01a23e28..2d0968b6 100644 --- a/advanced/Scripts/dnsmasq_parse.py +++ b/advanced/Scripts/dnsmasq_parse.py @@ -147,21 +147,22 @@ logfile = sys.argv[1] # Create the SQLite connection conn = sqlite3.connect('/etc/pihole/pihole.db') -c = conn.cursor() -create_tables() +with conn: + c = conn.cursor() -# Parse the log file. -for line in open(logfile): - line = line.rstrip() + create_tables() - if ': query[' in line: - parse_query(line) + # Parse the log file. + for line in open(logfile): + line = line.rstrip() - elif ': forwarded ' in line: - parse_forward(line) + if ': query[' in line: + parse_query(line) - elif (': reply ' in line) or (': cached ' in line): - parse_reply(line) + elif ': forwarded ' in line: + parse_forward(line) + + elif (': reply ' in line) or (': cached ' in line): + parse_reply(line) -conn.commit() diff --git a/advanced/Scripts/gravity_parse.py b/advanced/Scripts/gravity_parse.py index 4ac51563..40330c8e 100644 --- a/advanced/Scripts/gravity_parse.py +++ b/advanced/Scripts/gravity_parse.py @@ -18,7 +18,7 @@ import sqlite3 logfile = '/etc/pihole/pihole.2.eventHorizon.txt' # Create the SQLite connection -conn = sqlite3.connect('/etc/pihole/gravity.db') +conn = sqlite3.connect('/etc/pihole/pihole.db') # Python auto-handle commits, no need to call for commits manually with conn: