You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import tarfile
|
|
import psycopg
|
|
import json
|
|
import datetime
|
|
|
|
with psycopg.connect("host=192.168.2.97 port=7654 dbname=buscribe_db user=vst password=flnMSYPRf") as conn:
|
|
|
|
# Open a cursor to perform database operations
|
|
with conn.cursor() as cur:
|
|
|
|
# tar = tarfile.open("chat-2021-11-17.tar.gz")
|
|
tar = tarfile.open("db2021-chat.tar.gz")
|
|
|
|
with cur.copy("COPY chat (id, pub_time, content) FROM STDIN") as copy:
|
|
for ti in tar:
|
|
if not ti.isreg():
|
|
continue
|
|
|
|
f = tar.extractfile(ti)
|
|
|
|
for line in f:
|
|
linej = json.loads(line)
|
|
if linej["command"] == "PRIVMSG":
|
|
last_line = linej
|
|
|
|
copy.write_row((linej["tags"]["id"], datetime.datetime.utcfromtimestamp(linej["time"]), line.decode()))
|
|
|
|
# print(last_line["time"])
|
|
|
|
|
|
# cur.executemany(
|
|
# "INSERT INTO chat (id, content) VALUES (%s, %s) ON CONFLICT DO NOTHING",
|
|
# lines
|
|
# )
|
|
|
|
# for ti in tar:
|
|
# print(ti)
|
|
|
|
tar.close() |