aboutsummaryrefslogtreecommitdiffstats
path: root/common.py
blob: e45b5f00abdfd594186cee1a26bba3ae9c0d6dce (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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