Add SQLite database
This commit is contained in:
parent
e6f40ac0a6
commit
23491f17c7
|
@ -1,3 +1,4 @@
|
|||
DB_PATH=data/database.sqlite3
|
||||
MATRIX_HOMESERVER_URL=https://matrix.org
|
||||
MATRIX_FULL_USER_ID=@fckidiots:matrix.org
|
||||
MATRIX_PASSWORD=...
|
||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1,5 @@
|
|||
__pycache__/
|
||||
|
||||
/.env
|
||||
/data/
|
||||
!/data/.keep
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
FROM ubuntu:22.10
|
||||
RUN mkdir -p /app/mirrortea/
|
||||
RUN mkdir -p /app/data/ /app/mirrortea/
|
||||
WORKDIR /app
|
||||
RUN apt-get update --yes
|
||||
RUN apt-get install --yes python3 python3-pip
|
||||
|
|
|
@ -5,4 +5,5 @@ services:
|
|||
build: .
|
||||
env_file: '.env'
|
||||
volumes:
|
||||
- './mirrortea:/app/mirrortea/'
|
||||
- './data/:/app/data/'
|
||||
- './mirrortea/:/app/mirrortea/'
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import asyncio
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
import aiogram as telegram
|
||||
|
@ -7,6 +8,7 @@ import nio as matrix
|
|||
|
||||
def main():
|
||||
config = Config(
|
||||
db_path=os.environ['DB_PATH'],
|
||||
matrix_homeserver_url=os.environ['MATRIX_HOMESERVER_URL'],
|
||||
matrix_full_user_id=os.environ['MATRIX_FULL_USER_ID'],
|
||||
matrix_password=os.environ['MATRIX_PASSWORD'],
|
||||
|
@ -17,6 +19,7 @@ def main():
|
|||
|
||||
class Config:
|
||||
def __init__(self, **kwargs):
|
||||
self.db_path = kwargs['db_path']
|
||||
self.matrix_homeserver_url = kwargs['matrix_homeserver_url']
|
||||
self.matrix_full_user_id = kwargs['matrix_full_user_id']
|
||||
self.matrix_password = kwargs['matrix_password']
|
||||
|
@ -25,6 +28,7 @@ class Config:
|
|||
class Application:
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
self.sqlite_adapter = SqliteAdapter(config.db_path)
|
||||
self.matrix_loop = MatrixLoop(
|
||||
self,
|
||||
config.matrix_homeserver_url,
|
||||
|
@ -79,5 +83,11 @@ class TelegramLoop:
|
|||
async def on_message(self, msg):
|
||||
print(msg, file=sys.stderr)
|
||||
|
||||
class SqliteAdapter:
|
||||
def __init__(self, app, path):
|
||||
self.app = app
|
||||
self.path = path
|
||||
self.conn = sqlite3.connect(path)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Reference in a new issue