Initial release

This commit is contained in:
etienne-hd
2025-08-21 23:50:34 +02:00
commit dfbbcbdbbb
15 changed files with 618 additions and 0 deletions

36
searcher/id.py Normal file
View File

@@ -0,0 +1,36 @@
from .logger import logger
from typing import List, Final
import os
import json
MAX_ID: Final[int] = 10_000
class ID:
def __init__(self):
self._ids: List[str] = self._get_ids()
@property
def ids(self) -> List[str]:
return self._ids
def _get_ids(self) -> List[str]:
ids: List[str] = []
if os.path.exists("id.json"):
with open("id.json", "r") as f:
try:
ids = json.load(f)
except json.JSONDecodeError:
os.remove("id.json")
except:
logger.exception("An error occurred while attempting to open the id.json file.")
return ids
def add(self, id: str) -> bool:
if not id in self._ids:
self._ids.append(id)
with open("id.json", "w") as f:
json.dump(self._ids[-MAX_ID:], f, indent=3)
self._ids = self._ids[-MAX_ID:]
return True
return False