전체 메서드명 일관성 수정

This commit is contained in:
2023-04-27 23:44:08 +09:00
parent 2f563e4324
commit b91f5fd67d
2 changed files with 27 additions and 37 deletions

View File

@ -1,4 +1,3 @@
import asyncio
from aiohttp import web
from damination import DaminationAPI
@ -9,6 +8,11 @@ toonat = DaminationAPI()
app = web.Application()
@routes.get('/get_subscriber')
async def get_widgets(request):
subscribers = toonat.get_subscribers()
return web.json_response(subscribers)
@routes.get('/subscribe/{widget_id}/{url}')
async def subscribe(request):
widget_id = request.match_info['widget_id']
@ -29,19 +33,6 @@ async def unsubscribe(request):
else:
return web.Response(text=f"Not subscribed to widget ID {widget_id} with URL {url}.")
@routes.get('/init_widget_id')
async def init_widget_id(request):
if not toonat.WIDGET_IDS:
widget_id = request.query.get("widget_id")
if widget_id:
toonat.WIDGET_IDS.append(widget_id)
return web.Response(text=f"Widget ID {widget_id} added.")
else:
return web.Response(text="Invalid widget ID. Please try again.")
else:
return web.Response(text="Widget ID already exists.")
@routes.get('/get_widgets')
async def get_widgets(request):
"""
@ -58,11 +49,8 @@ async def add_widget(request):
widget_id: 추가할 위젯 ID
"""
widget_id = request.match_info['widget_id']
result = await toonat.add_widget_id_and_start_fetching(widget_id)
if result:
return web.Response(text=f"Widget ID {widget_id} added and fetching started.")
else:
return web.Response(text=f"Widget ID {widget_id} already exists in the list.")
await toonat.add_widget_and_start_fetching_notifications(widget_id)
return web.Response(text=f"Widget ID {widget_id} added and fetching started.")
@routes.get('/remove_widget/{widget_id}')
async def remove_widget(request):
@ -71,7 +59,7 @@ async def remove_widget(request):
widget_id: 제거할 위젯 ID
"""
widget_id = request.match_info['widget_id']
await toonat.remove_widget_id_and_stop_fetching(widget_id)
await toonat.remove_widget_and_stop_fetching_notifications(widget_id)
return web.Response(text=f"Widget ID {widget_id} removed and fetching stopped.")
@routes.get('/status')
@ -101,7 +89,6 @@ async def main():
# 웹 서버를 실행합니다.
web_server_task = asyncio.create_task(web_server(app))
# 두 작업을 병렬로 실행하지 않고 순서대로 처리합니다.
await api_task
await web_server_task
@ -110,6 +97,6 @@ async def main():
if __name__ == "__main__":
if not toonat.WIDGET_IDS:
print("No widget ID found in settings.ini.")
print("Please enter the widget ID via web endpoint (http://localhost/init_widget_id?widget_id=YOUR_WIDGET_ID)")
print("Please enter the widget ID via web endpoint (http://localhost/add_widget/YOUR_WIDGET_ID)")
asyncio.run(main())