mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-07-04 12:03:03 +02:00
feat: made it uvicorn fast api compliant
This commit is contained in:
parent
d35aa59a25
commit
0075c4de82
17
main.py
17
main.py
@ -5,17 +5,15 @@ import requests
|
|||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
from datetime import datetime, time, timedelta
|
from datetime import datetime, time, timedelta
|
||||||
# from rule34Py import rule34Py
|
from fastapi import FastAPI
|
||||||
# r34Py = rule34Py()
|
|
||||||
|
|
||||||
|
# Create FastAPI app
|
||||||
|
app = FastAPI()
|
||||||
|
|
||||||
|
PHONE_NUMBER = os.getenv('PHONE_NUMBER', '1234567890')
|
||||||
# Set up environment variable for the phone number
|
|
||||||
PHONE_NUMBER = os.getenv('PHONE_NUMBER', '1234567890') # Default to '1234567890' if not set
|
|
||||||
RECEIVE_URL = f"http://localhost:9922/v1/receive/{PHONE_NUMBER}"
|
RECEIVE_URL = f"http://localhost:9922/v1/receive/{PHONE_NUMBER}"
|
||||||
REMOVE_ATTACHMENT_URL = f"http://localhost:9922/v1/attachments/"
|
REMOVE_ATTACHMENT_URL = f"http://localhost:9922/v1/attachments/"
|
||||||
SEND_URL = 'http://localhost:9922/v2/send'
|
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 = os.getenv('GROUP_ID', '')
|
||||||
GROUP_ID_SEND = os.getenv('GROUP_ID_SEND', '')
|
GROUP_ID_SEND = os.getenv('GROUP_ID_SEND', '')
|
||||||
CAT_API = os.getenv('CAT_API', '')
|
CAT_API = os.getenv('CAT_API', '')
|
||||||
@ -240,11 +238,10 @@ async def listen_to_server(counter):
|
|||||||
except websockets.ConnectionClosed as e:
|
except websockets.ConnectionClosed as e:
|
||||||
print(f"Connection closed: {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()
|
counter = StringCounter()
|
||||||
task1 = asyncio.create_task(listen_to_server(counter))
|
task1 = asyncio.create_task(listen_to_server(counter))
|
||||||
task2 = asyncio.create_task(scheduled_task(counter))
|
task2 = asyncio.create_task(scheduled_task(counter))
|
||||||
await asyncio.gather(task1, task2)
|
await asyncio.gather(task1, task2)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
asyncio.run(main())
|
|
||||||
|
|||||||
@ -5,4 +5,5 @@ uvicorn
|
|||||||
asyncio
|
asyncio
|
||||||
websockets
|
websockets
|
||||||
requests
|
requests
|
||||||
rule34py
|
rule34py
|
||||||
|
fastapi
|
||||||
Loading…
Reference in New Issue
Block a user