Compare commits

..
5 Commits
Author SHA1 Message Date
C 005bf87df5 add initial review testing for sql 2025-10-11 11:39:29 -07:00
C aa8883c822 rate limit 2025-10-11 11:39:12 -07:00
C 53994f99dc move throttler example. we dont need it in src 2025-10-11 11:38:54 -07:00
C 0f8b9b444b this is the schedule manager not the db 2025-10-11 11:33:14 -07:00
C 90ca36f426 big sexy sqlite db 2025-10-11 11:33:00 -07:00
5 changed files with 88 additions and 6 deletions

No files matched your search

+33 -4
View File
@@ -4,6 +4,12 @@ import json
import asyncio
import uuid
import re
from time import time
import re
# we dont need no stinkin floats
time = int(time())
import db
import get_sq_env
@@ -114,15 +120,37 @@ async def acat2id(cat_id: str):
return items
async def do_review() -> bool:
result = await acat2id(LEGO_CAT_ID)
for item in result:
if not re.match(r".*\d{5}.*", item["name"]):
missing = []
print(f"{item} is missing its set number!")
print(f"[@DEBUG] Upserting {item['id']} into REVIEW table")
item_sanitized = {
"sq_object": item["id"],
"set_name": item["name"],
"set_number": None,
"time_added": time
}
missing.append(item_sanitized)
for item in missing:
sq_item = await db.fetch(item["id"]) #
if item["id"] != sq_item["sq_object"]:
await db.upsert("REVIEW", item_sanitized, "sq_object")
print(f"[@DEBUG] Upserted {item['id']} into REVIEW table")
print(f"[@DEBUG] {item['id']} already in REVIEW table")
return True
async def test() -> None:
task = asyncio.create_task(acat2id(LEGO_CAT_ID)) # type: ignore
await do_review()
await asyncio.sleep(1) # Give the task some time to complete
result = await task
print("OBJECTS IN LEGO CATEGORY:")
for item in result:
print(f"ID: {item['id']}, Name: {item['name']}")
# eturn
#print("OBJECTS IN LEGO CATEGORY:")
#print(f"ID: {item['id']}, Name: {item['name']}")
return True
# pass
@@ -134,6 +162,7 @@ async def test() -> None:
if __name__ == "__main__":
print("Spooling up..")
print(f"@[DEBUG] ENV:\t{ENVIRONMENT}")
print(f"@[DEBUG] CATID:\t{LEGO_CAT_ID}")
asyncio.run(test())
+2 -2
View File
@@ -33,9 +33,9 @@ def get_set(set_number: int) -> dict:
response = requests.get(url)
if response.status_code == 200:
data = response.json()
if not data["sets"] and if data["message"] == "API limit exceeded":
if not data["sets"] and data["message"] == "API limit exceeded":
raise Exception("API limit exceeded. Please try again later.")
break
return False
print(f"[@DEBUG]\t{data}")
our_set = {
+53
View File
@@ -0,0 +1,53 @@
import aiosqlite
from time import time
time = int(time()) # we dont need no stinkin floats
# db = await aiosqlite.connect("edderkop.db") # type: ignore
async def fetch(sqobj):
"""
Asynchronously fetch a record from the REVIEW table by sq_object.
Args:
sqobj (str): The sq_object identifier to search for.
Returns:
dict or None: The fetched record as a dictionary, or None if not found.
"""
async with aiosqlite.connect("edderkop.db") as db: # type: ignore
db.row_factory = aiosqlite.Row # type: ignore
async with db.execute(
"SELECT * FROM REVIEW WHERE sq_object = ?", (sqobj,)
) as cursor:
row = await cursor.fetchone()
if row:
return dict(row)
return None
async def upsert(table: str, data: dict, unique_key: str) -> None:
"""
Asynchronously insert or update a record in the specified table.
Args:
sq_ib (aiosqlite.Connection): The SQLite database connection.
table (str): The name of the table to upsert into.
data (dict): A dictionary of column-value pairs to insert or update.
unique_key (str): The column name that serves as the unique key for upsert.
Returns:
None
"""
print(f"Upserting into {table}: {data}")
columns = ', '.join(data.keys())
placeholders = ', '.join('?' * len(data))
updates = ', '.join(f"{col}=excluded.{col}" for col in data.keys() if col != unique_key)
sql = f"""
INSERT INTO {table} ({columns})
VALUES ({placeholders})
ON CONFLICT({unique_key}) DO UPDATE SET
{updates};
"""
async with aiosqlite.connect("edderkop.db") as db: # type: ignore
async with db.execute(sql, tuple(data.values())) as cursor:
await db.commit()
#await db.close()
File renamed without changes.
File renamed without changes.