Add SQLite database

This commit is contained in:
Alex Kotov 2023-01-09 00:39:15 +04:00
parent e6f40ac0a6
commit 23491f17c7
No known key found for this signature in database
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 16 additions and 2 deletions

View file

@ -1,3 +1,4 @@
DB_PATH=data/database.sqlite3
MATRIX_HOMESERVER_URL=https://matrix.org MATRIX_HOMESERVER_URL=https://matrix.org
MATRIX_FULL_USER_ID=@fckidiots:matrix.org MATRIX_FULL_USER_ID=@fckidiots:matrix.org
MATRIX_PASSWORD=... MATRIX_PASSWORD=...

2
.gitignore vendored
View file

@ -1,3 +1,5 @@
__pycache__/ __pycache__/
/.env /.env
/data/
!/data/.keep

View file

@ -1,5 +1,5 @@
FROM ubuntu:22.10 FROM ubuntu:22.10
RUN mkdir -p /app/mirrortea/ RUN mkdir -p /app/data/ /app/mirrortea/
WORKDIR /app WORKDIR /app
RUN apt-get update --yes RUN apt-get update --yes
RUN apt-get install --yes python3 python3-pip RUN apt-get install --yes python3 python3-pip

View file

@ -5,4 +5,5 @@ services:
build: . build: .
env_file: '.env' env_file: '.env'
volumes: volumes:
- './mirrortea:/app/mirrortea/' - './data/:/app/data/'
- './mirrortea/:/app/mirrortea/'

View file

@ -1,5 +1,6 @@
import asyncio import asyncio
import os import os
import sqlite3
import sys import sys
import aiogram as telegram import aiogram as telegram
@ -7,6 +8,7 @@ import nio as matrix
def main(): def main():
config = Config( config = Config(
db_path=os.environ['DB_PATH'],
matrix_homeserver_url=os.environ['MATRIX_HOMESERVER_URL'], matrix_homeserver_url=os.environ['MATRIX_HOMESERVER_URL'],
matrix_full_user_id=os.environ['MATRIX_FULL_USER_ID'], matrix_full_user_id=os.environ['MATRIX_FULL_USER_ID'],
matrix_password=os.environ['MATRIX_PASSWORD'], matrix_password=os.environ['MATRIX_PASSWORD'],
@ -17,6 +19,7 @@ def main():
class Config: class Config:
def __init__(self, **kwargs): def __init__(self, **kwargs):
self.db_path = kwargs['db_path']
self.matrix_homeserver_url = kwargs['matrix_homeserver_url'] self.matrix_homeserver_url = kwargs['matrix_homeserver_url']
self.matrix_full_user_id = kwargs['matrix_full_user_id'] self.matrix_full_user_id = kwargs['matrix_full_user_id']
self.matrix_password = kwargs['matrix_password'] self.matrix_password = kwargs['matrix_password']
@ -25,6 +28,7 @@ class Config:
class Application: class Application:
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
self.sqlite_adapter = SqliteAdapter(config.db_path)
self.matrix_loop = MatrixLoop( self.matrix_loop = MatrixLoop(
self, self,
config.matrix_homeserver_url, config.matrix_homeserver_url,
@ -79,5 +83,11 @@ class TelegramLoop:
async def on_message(self, msg): async def on_message(self, msg):
print(msg, file=sys.stderr) 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__': if __name__ == '__main__':
main() main()