Mbonea commited on
Commit
fa1fb30
1 Parent(s): 0d42d18
App/6183919505.session CHANGED
Binary files a/App/6183919505.session and b/App/6183919505.session differ
 
App/Analytics/Model.py CHANGED
@@ -1,5 +1,5 @@
1
  import asyncio
2
- import orm
3
  import psycopg2
4
  import datetime
5
  import pydantic
 
1
  import asyncio
2
+ from App.modelInit import orm
3
  import psycopg2
4
  import datetime
5
  import pydantic
App/Transcription/Model.py CHANGED
@@ -1,4 +1,4 @@
1
- import orm
2
  import datetime
3
  from App.modelInit import database, models
4
  from App.Users.Model import User
 
1
+ from App.modelInit import orm
2
  import datetime
3
  from App.modelInit import database, models
4
  from App.Users.Model import User
App/UserTranscriptions/UserTranscriptionsRoutes.py CHANGED
@@ -1,6 +1,7 @@
1
  from fastapi import APIRouter
2
  from .Schemas import BaseRequest, GetTranscriptions
3
  from .Model import UserTranscriptions
 
4
  from App.Users.Model import User
5
 
6
  user_transcriptions_router = APIRouter(tags=["user-transcriptions"])
 
1
  from fastapi import APIRouter
2
  from .Schemas import BaseRequest, GetTranscriptions
3
  from .Model import UserTranscriptions
4
+ from App.modelInit import models
5
  from App.Users.Model import User
6
 
7
  user_transcriptions_router = APIRouter(tags=["user-transcriptions"])
App/Users/Model.py CHANGED
@@ -1,5 +1,5 @@
1
  import asyncio
2
- import orm
3
  import psycopg2
4
  import datetime
5
  import pydantic
 
1
  import asyncio
2
+ from App.modelInit import orm
3
  import psycopg2
4
  import datetime
5
  import pydantic
App/__init__.py CHANGED
@@ -1,5 +1,7 @@
1
  import uuid, contextvars
2
  from telethon import TelegramClient
 
 
3
  import os
4
 
5
  print(os.getcwd())
 
1
  import uuid, contextvars
2
  from telethon import TelegramClient
3
+
4
+
5
  import os
6
 
7
  print(os.getcwd())
App/__main__.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # from App.app import app
2
+ from App.modelInit import models, dbLink
3
+ import asyncio
4
+ from sqlalchemy.ext.asyncio import create_async_engine
5
+
6
+
7
+ async def async_main() -> None:
8
+ engine = create_async_engine(
9
+ dbLink,
10
+ echo=True,
11
+ )
12
+
13
+ async with engine.begin() as conn:
14
+ await conn.run_sync(models.metadata.create_all)
15
+
16
+
17
+ import uvicorn
18
+
19
+
20
+ async def create_tables():
21
+ await async_main()
22
+
23
+
24
+ if __name__ == "__main__":
25
+ loop = asyncio.get_event_loop()
26
+ loop.run_until_complete(create_tables())
27
+ loop.close()
28
+ uvicorn.run(app, host="0.0.0.0", port=7860)
App/app.py CHANGED
@@ -8,7 +8,7 @@ from .Streaming.StreamingRoutes import streaming_router
8
  from .UserTranscriptions.UserTranscriptionsRoutes import user_transcriptions_router
9
  from .Monitor.monitorRoutes import monitor_router
10
  from fastapi.middleware.cors import CORSMiddleware
11
- import logging
12
 
13
 
14
  # Configure logging
@@ -18,8 +18,17 @@ logging.basicConfig(
18
  datefmt="%Y-%m-%d %H:%M:%S",
19
  )
20
 
21
- app = FastAPI()
22
 
 
 
 
 
 
 
 
 
 
 
23
  origins = ["*"]
24
 
25
  app.add_middleware(
@@ -33,9 +42,10 @@ app.add_middleware(
33
 
34
  @app.on_event("startup")
35
  async def startup_event():
36
- await bot.start(bot_token="6183919505:AAEhHFt4mI18bQeAf2Lj7AePXFRPVLrOFM8")
37
  # await upload_bot.start()
38
- # await models.create_all()
 
39
  if not database.is_connected:
40
  await database.connect()
41
  print("connected!")
@@ -43,8 +53,8 @@ async def startup_event():
43
 
44
  @app.on_event("shutdown")
45
  async def shutdown_event():
46
- await bot.session.save()
47
- await bot.disconnect()
48
 
49
  # await upload_bot.stop()
50
  if not database.is_connected:
 
8
  from .UserTranscriptions.UserTranscriptionsRoutes import user_transcriptions_router
9
  from .Monitor.monitorRoutes import monitor_router
10
  from fastapi.middleware.cors import CORSMiddleware
11
+ import logging, orm
12
 
13
 
14
  # Configure logging
 
18
  datefmt="%Y-%m-%d %H:%M:%S",
19
  )
20
 
 
21
 
22
+ async def create_async_model(model):
23
+ import asyncio
24
+
25
+ # until something better comes along
26
+ url = model._get_database_url()
27
+ await asyncio.gather(asyncio.create_task(model._create_all(url)))
28
+
29
+
30
+ app = FastAPI()
31
+ models = orm.ModelRegistry(database=database)
32
  origins = ["*"]
33
 
34
  app.add_middleware(
 
42
 
43
  @app.on_event("startup")
44
  async def startup_event():
45
+ # await bot.start(bot_token="6183919505:AAEhHFt4mI18bQeAf2Lj7AePXFRPVLrOFM8")
46
  # await upload_bot.start()
47
+ # models.create_all()
48
+ # await create_async_model(models)
49
  if not database.is_connected:
50
  await database.connect()
51
  print("connected!")
 
53
 
54
  @app.on_event("shutdown")
55
  async def shutdown_event():
56
+ # await bot.session.save()
57
+ # await bot.disconnect()
58
 
59
  # await upload_bot.stop()
60
  if not database.is_connected:
App/modelInit.py CHANGED
@@ -1,22 +1,26 @@
1
  import databases
2
- import orm
3
- import psycopg2
4
 
5
 
6
-
7
-
8
- #deployment
9
- database = databases.Database(
10
- "postgresql+asyncpg://postgres:[email protected]:5432/postgres"
11
- )
12
-
13
-
14
- #development
15
-
16
  # database = databases.Database(
17
- # "postgresql+asyncpg://postgres:zJAkapOh3IVt8R0h@db.mygpwobpwxttmilnxrtu.supabase.co:5432/postgres"
18
  # )
19
 
20
 
 
 
 
 
21
 
22
  models = orm.ModelRegistry(database=database)
 
 
 
 
 
 
 
 
 
 
 
1
  import databases
2
+ import orm, asyncio
 
3
 
4
 
5
+ # deployment
 
 
 
 
 
 
 
 
 
6
  # database = databases.Database(
7
+ # "postgresql+asyncpg://postgres:PkkneZrSFsnJR6B@db.vfhoydxvxuesxhrcdnmx.supabase.co:5432/postgres"
8
  # )
9
 
10
 
11
+ # development
12
+ dbLink = "postgresql+asyncpg://postgres:[email protected]:5432/postgres"
13
+ database = databases.Database(dbLink)
14
+
15
 
16
  models = orm.ModelRegistry(database=database)
17
+
18
+
19
+ class Note(orm.Model):
20
+ tablename = "notes"
21
+ registry = models
22
+ fields = {
23
+ "id": orm.Integer(primary_key=True),
24
+ "text": orm.String(max_length=100),
25
+ "completed": orm.Boolean(default=False),
26
+ }
Dockerfile CHANGED
@@ -17,7 +17,7 @@ USER user
17
  COPY --chown=user . /srv
18
 
19
  # Command to run the application
20
- CMD uvicorn App.app:app --host 0.0.0.0 --port 7860 & celery -A App.Worker.celery worker -c 8 --loglevel=info
21
 
22
  # Expose the server port
23
  EXPOSE 7860
 
17
  COPY --chown=user . /srv
18
 
19
  # Command to run the application
20
+ CMD python -m App & celery -A App.Worker.celery worker -c 8 --loglevel=info
21
 
22
  # Expose the server port
23
  EXPOSE 7860