aboutsummaryrefslogtreecommitdiffstats
path: root/common.py
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-11-21 22:30:47 -0800
committerPinapelz <yukais@pinapelz.com>2025-11-21 23:27:30 -0800
commit22714994d2b7cfa238c8b2d54a3639cd6417e9b6 (patch)
treedc7036309fbb35376f452f44e33bfbe9c2e18c61 /common.py
parenta7347217899fb7a3addcee58a9fbee4a0c07ff57 (diff)
scaffold implementation for remote sqlite db
Diffstat (limited to 'common.py')
-rw-r--r--common.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/common.py b/common.py
new file mode 100644
index 0000000..e45b5f0
--- /dev/null
+++ b/common.py
@@ -0,0 +1,15 @@
+from database.local_database import Database as LocalDatabase
+from database.remote_database import RemoteDatabase
+import os
+
+def create_database_connection():
+ sqlite_db = os.getenv("SQLITE_DB")
+ if sqlite_db is None or sqlite_db == "":
+ return LocalDatabase("news.db")
+ elif sqlite_db.endswith(".db"):
+ return LocalDatabase(sqlite_db)
+ else:
+ auth_token = os.getenv("REMOTE_AUTH_TOKEN")
+ if not auth_token:
+ raise RuntimeError("Remote DB was specified but no auth token was provided")
+ return RemoteDatabase(url=sqlite_db, auth_token=auth_token)
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage