mirror of
https://github.com/pi-hole/pi-hole.git
synced 2025-04-16 12:29:03 +00:00
Commits squashed, lots of changes.
This commit is contained in:
parent
2e331cbd73
commit
e6873e0ebd
1 changed files with 13 additions and 34 deletions
|
@ -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,))
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue