-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
30 lines (28 loc) · 1.25 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import re
import time
import sqlite3
conn = sqlite3.connect('/Users/kyriakos/PycharmProjects/ircbot/ircbot.sqlite3')
curs = conn.cursor()
curs.execute('''CREATE TABLE IF NOT EXISTS QUOTES (ID INTEGER PRIMARY KEY,
NICK TEXT,
QUOTE TEXT collate nocase,
QUOTE_DT NUMERIC,
ADDED_BY TEXT,
CHANNEL TEXT
)''')
with open('/Users/kyriakos/PycharmProjects/ircbot/quotes.txt', 'r') as f:
for line in f:
nick_match = re.match(r'\S*\s*<(\S*)>.*', line)
if nick_match:
nick = nick_match.groups()[0]
else:
nick = ''
quote = line.strip()
quote_dt = int(time.time())
inserted_by = 'import_tool'
channel = '#other'
x = curs.execute(''' INSERT INTO QUOTES (NICK, QUOTE, QUOTE_DT, ADDED_BY, CHANNEL) VALUES (?, ?, ?, ?, ?)''',
(nick, quote, quote_dt, inserted_by, channel))
print time.time()
conn.commit()
print time.time()