-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
875 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python Debugger: Current File", | ||
"type": "debugpy", | ||
"request": "launch", | ||
"program": "${file}", | ||
"console": "integratedTerminal" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import sqlite3 | ||
import threading | ||
from datetime import datetime | ||
|
||
thread_local = threading.local() | ||
|
||
|
||
def get_db_connection(): | ||
if not hasattr(thread_local, "connection"): | ||
thread_local.connection = sqlite3.connect("messages.db") | ||
return thread_local.connection | ||
|
||
|
||
def initialize_database(): | ||
conn = get_db_connection() | ||
c = conn.cursor() | ||
|
||
c.execute( | ||
"""CREATE TABLE IF NOT EXISTS message ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
message_id INTEGER NOT NULL, | ||
sender TEXT NOT NULL, | ||
sender_short_name TEXT NOT NULL, | ||
sender_long_name TEXT NOT NULL, | ||
reply_id INTEGER NOT NULL, | ||
channel INTEGER NOT NULL, | ||
date TEXT NOT NULL, | ||
content TEXT NOT NULL | ||
);""" | ||
) | ||
c.execute( | ||
"""CREATE TABLE IF NOT EXISTS channels ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name TEXT NOT NULL, | ||
url TEXT NOT NULL | ||
);""" | ||
) | ||
conn.commit() | ||
print("Database schema initialized.") | ||
|
||
|
||
def add_channel(name, url): | ||
conn = get_db_connection() | ||
c = conn.cursor() | ||
c.execute("INSERT INTO channels (name, url) VALUES (?, ?)", (name, url)) | ||
conn.commit() | ||
|
||
|
||
def get_channels(): | ||
conn = get_db_connection() | ||
c = conn.cursor() | ||
c.execute("SELECT name, url FROM channels") | ||
return c.fetchall() | ||
|
||
|
||
def add_message( | ||
message_id, | ||
sender_id, | ||
sender_short_name, | ||
sender_long_name, | ||
reply_id, | ||
channel, | ||
content, | ||
): | ||
conn = get_db_connection() | ||
c = conn.cursor() | ||
date = datetime.now().strftime("%Y-%m-%d %H:%M") | ||
|
||
c.execute( | ||
"INSERT INTO message (message_id, sender, sender_short_name, sender_long_name, reply_id, " | ||
"channel, date, content) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", | ||
( | ||
message_id, | ||
sender_id, | ||
sender_short_name, | ||
sender_long_name, | ||
reply_id, | ||
channel, | ||
date, | ||
content, | ||
), | ||
) | ||
return conn.commit() | ||
|
||
|
||
def get_messages(top: int = 5): | ||
conn = get_db_connection() | ||
c = conn.cursor() | ||
c.execute( | ||
"SELECT id, sender_short_name, sender_long_name, date, channel, " | ||
"content FROM message ORDER BY date DESC LIMIT ?", | ||
(top,), | ||
) | ||
return c.fetchall() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from datetime import datetime | ||
|
||
|
||
def log_timestamp(): | ||
return datetime.now().strftime("%Y-%m-%d %H:%M:%S") | ||
return datetime.now().strftime("%Y-%m-%d %H:%M:%S") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.