Skip to content

Commit

Permalink
--amend
Browse files Browse the repository at this point in the history
  • Loading branch information
doombeaker committed Sep 8, 2024
1 parent 0e47575 commit bbfc677
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions showcase.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import urllib.error
import urllib.request

import aiohttp
import server
from aiohttp import web

Expand All @@ -12,18 +13,19 @@
SHOW_CASES = {}


def get_bizyair_news(base_url="https://bizyair.siliconflow.cn"):
async def get_bizyair_news(base_url="https://bizyair.siliconflow.cn"):
url = f"{base_url}/bznews.json"
try:
response = urllib.request.urlopen(url, timeout=5)
if response.getcode() == 200:
data = response.read()
return json.loads(data)
else:
print(f"Failed to fetch news.json: HTTP Status {response.getcode()}")
return {}
except urllib.error.URLError as e:
print(f"Error fetching news.json: {e.reason}")
async with aiohttp.ClientSession() as session:
async with session.get(url, timeout=5) as response:
if response.status == 200:
data = await response.text()
return json.loads(data)
else:
print(f"Failed to fetch news.json: HTTP Status {response.status}")
return {}
except aiohttp.ClientError as e:
print(f"Error fetching news.json: {e}")
return {}
except Exception as e:
print(f"Error fetching BizyAir news.json: {str(e)}")
Expand Down Expand Up @@ -61,7 +63,7 @@ async def set_api_key_page(request):
@PromptServer.instance.routes.get("/bizyair/news")
async def list_news(request):
return web.Response(
text=json.dumps(get_bizyair_news(), ensure_ascii=False),
text=json.dumps(await get_bizyair_news(), ensure_ascii=False),
content_type="application/json",
)

Expand Down

0 comments on commit bbfc677

Please sign in to comment.