feat: made it uvicorn fast api compliant

This commit is contained in:
Krzysztof Rudnicki 2024-10-11 19:27:15 +02:00
parent d35aa59a25
commit 0075c4de82
3 changed files with 10 additions and 12 deletions

17
main.py
View File

@ -5,17 +5,15 @@ import requests
import base64
import json
from datetime import datetime, time, timedelta
# from rule34Py import rule34Py
# r34Py = rule34Py()
from fastapi import FastAPI
# Create FastAPI app
app = FastAPI()
# Set up environment variable for the phone number
PHONE_NUMBER = os.getenv('PHONE_NUMBER', '1234567890') # Default to '1234567890' if not set
PHONE_NUMBER = os.getenv('PHONE_NUMBER', '1234567890')
RECEIVE_URL = f"http://localhost:9922/v1/receive/{PHONE_NUMBER}"
REMOVE_ATTACHMENT_URL = f"http://localhost:9922/v1/attachments/"
SEND_URL = 'http://localhost:9922/v2/send'
LIST_SIGNAL_GROUPS = f"http://localhost:9922/v1/groups/${PHONE_NUMBER}"
GROUP_ID = os.getenv('GROUP_ID', '')
GROUP_ID_SEND = os.getenv('GROUP_ID_SEND', '')
CAT_API = os.getenv('CAT_API', '')
@ -240,11 +238,10 @@ async def listen_to_server(counter):
except websockets.ConnectionClosed as e:
print(f"Connection closed: {e}")
async def main():
# Endpoint to start the asyncio server tasks
@app.on_event("startup")
async def start_tasks():
counter = StringCounter()
task1 = asyncio.create_task(listen_to_server(counter))
task2 = asyncio.create_task(scheduled_task(counter))
await asyncio.gather(task1, task2)
if __name__ == "__main__":
asyncio.run(main())

View File

@ -5,4 +5,5 @@ uvicorn
asyncio
websockets
requests
rule34py
rule34py
fastapi

2
run.sh
View File

@ -1,3 +1,3 @@
#!/bin/sh
sudo apt-get install python3-venv
uvicorn main:app --host 0.0.0.0 --port 8000 --reload