Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a proper sqlite3 database to RootPythia #44

Merged
merged 20 commits into from
Aug 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add DB_FOLDER and create the sqlite3 Connection object in DummyDBManager
  • Loading branch information
ctmbl committed Dec 22, 2023
commit 87ac075fa38e9b46919cb04b1ad590f13d24f23b
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -31,6 +31,12 @@ API_URL=https://api.www.root-me.org/
# [OPTIONAL] the maximum number of time a single request is retried (if relevant)
MAX_API_ATTEMPT=5


### Bot Configuration
# [OPTIONAL] in seconds, the delay between new solve checking (default is 10)
REFRESH_DELAY=


### Database Configuration
# the path to the Sqlite database folder
DB_FOLDER=data
15 changes: 13 additions & 2 deletions src/bot/dummy_db_manager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import logging
import sqlite3
from os import getenv, path

from classes import User
from classes import Challenge


DB_FOLDER = getenv("DB_FOLDER")


class InvalidUser(Exception):
def __init__(self, idx=None, message=None):
self.idx = idx
@@ -20,10 +25,16 @@ def __init__(self, idx=None, message=None):

class DummyDBManager:
def __init__(self, api_manager):
self.users = []
self.logger = logging.getLogger(__name__)

if DB_FOLDER is None or not path.isdir(DB_FOLDER):
self.logger.critical("DB_FOLDER: '%s', is not a directory")
raise Exception("DB_FOLDER: '%s', is not a directory")

self.db = sqlite3.connect(path.join(DB_FOLDER, "RootPythia.db"))

self.api_manager = api_manager

self.logger = logging.getLogger(__name__)

async def add_user(self, idx):
"""Call the API Manager to get a user by his id then create a User object and store it"""