had to change some things to get cursor for db working.
This commit is contained in:
parent
f70b2147cd
commit
7b32ee7fcf
3 changed files with 15 additions and 21 deletions
|
@ -1,6 +1,6 @@
|
||||||
import requests
|
import requests
|
||||||
from fediverse_factory import get_fediverse_service
|
from fediverse_factory import get_fediverse_service
|
||||||
from db_utils import get_db_connection
|
import db_utils
|
||||||
from config import RARITY_TO_WEIGHT
|
from config import RARITY_TO_WEIGHT
|
||||||
|
|
||||||
def add_character(name: str, rarity: int, weight: float, image_url: str) -> tuple[int, str]:
|
def add_character(name: str, rarity: int, weight: float, image_url: str) -> tuple[int, str]:
|
||||||
|
@ -47,20 +47,14 @@ def add_character(name: str, rarity: int, weight: float, image_url: str) -> tupl
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
raise RuntimeError(f"Failed to upload image: {e}") from e
|
raise RuntimeError(f"Failed to upload image: {e}") from e
|
||||||
|
|
||||||
# Insert into database
|
# Insert into database using the global connection pattern
|
||||||
conn = get_db_connection()
|
db_utils.CURSOR.execute(
|
||||||
cur = conn.cursor()
|
|
||||||
cur.execute(
|
|
||||||
'INSERT INTO characters (name, rarity, weight, file_id) VALUES (?, ?, ?, ?)',
|
'INSERT INTO characters (name, rarity, weight, file_id) VALUES (?, ?, ?, ?)',
|
||||||
(stripped_name, rarity, float(weight), file_id)
|
(stripped_name, rarity, float(weight), file_id)
|
||||||
)
|
)
|
||||||
conn.commit()
|
character_id = db_utils.CURSOR.lastrowid
|
||||||
character_id = cur.lastrowid
|
|
||||||
|
|
||||||
return character_id, file_id
|
return character_id, file_id
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise
|
raise
|
||||||
finally:
|
|
||||||
if 'conn' in locals():
|
|
||||||
conn.close()
|
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from parsing import parse_notification
|
from parsing import parse_notification
|
||||||
from db_utils import get_config, set_config
|
from db_utils import get_config, set_config, connect
|
||||||
from fediverse_factory import get_fediverse_service
|
from fediverse_factory import get_fediverse_service
|
||||||
import config
|
import config
|
||||||
|
|
||||||
def stream_notifications():
|
def stream_notifications():
|
||||||
|
# Initialize database connection
|
||||||
|
connect()
|
||||||
|
|
||||||
# Initialize the Fediverse service
|
# Initialize the Fediverse service
|
||||||
fediverse_service = get_fediverse_service()
|
fediverse_service = get_fediverse_service()
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,13 @@
|
||||||
DefaultAdmins = ['admin@example.tld']
|
DefaultAdmins = ['admin@example.tld']
|
||||||
; SQLite Database location
|
; SQLite Database location
|
||||||
DatabaseLocation = ./gacha_game.db
|
DatabaseLocation = ./gacha_game.db
|
||||||
|
; Instance type - either "misskey" or "pleroma"
|
||||||
|
InstanceType = misskey
|
||||||
|
; Web server port (default: 5000)
|
||||||
|
WebPort = 5000
|
||||||
|
; Comma-separated list of trusted fediverse instances (leave empty to allow only local users)
|
||||||
|
; Example: TrustedInstances = mastodon.social,misskey.io,pleroma.example.com
|
||||||
|
TrustedInstances =
|
||||||
|
|
||||||
[gacha]
|
[gacha]
|
||||||
; Number of seconds players have to wait between rolls
|
; Number of seconds players have to wait between rolls
|
||||||
|
@ -32,13 +39,3 @@ User = @bot@example.tld
|
||||||
; API key for the bot
|
; API key for the bot
|
||||||
; Generate one by going to Settings > API > Generate access token
|
; Generate one by going to Settings > API > Generate access token
|
||||||
Token = abcdefghijklmnopqrstuvwxyz012345
|
Token = abcdefghijklmnopqrstuvwxyz012345
|
||||||
|
|
||||||
; Instance type - either "misskey" or "pleroma"
|
|
||||||
InstanceType = misskey
|
|
||||||
|
|
||||||
; Web server port (default: 5000)
|
|
||||||
WebPort = 5000
|
|
||||||
|
|
||||||
; Comma-separated list of trusted fediverse instances (leave empty to allow only local users)
|
|
||||||
; Example: TrustedInstances = mastodon.social,misskey.io,pleroma.example.com
|
|
||||||
TrustedInstances =
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue