aboutsummaryrefslogtreecommitdiffstats
path: root/common.py
diff options
context:
space:
mode:
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