e
This commit is contained in:
parent
b049a61b73
commit
00000d93ca
1 changed files with 38 additions and 40 deletions
|
|
@ -71,7 +71,7 @@ async def get_cert(client: httpx.AsyncClient) -> ssl.SSLContext:
|
||||||
return ssl.create_default_context(cafile=CERT_FILE)
|
return ssl.create_default_context(cafile=CERT_FILE)
|
||||||
|
|
||||||
|
|
||||||
async def fetch_xml_stream(url: str, ssl_ctx: ssl.SSLContext) -> io.BytesIO:
|
async def fetch_xml_stream(url: str, ssl_ctx: ssl.SSLContext) -> io.BytesIO | None:
|
||||||
buffer = io.BytesIO()
|
buffer = io.BytesIO()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -87,8 +87,7 @@ async def fetch_xml_stream(url: str, ssl_ctx: ssl.SSLContext) -> io.BytesIO:
|
||||||
return buffer
|
return buffer
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.error(f"Failed to fetch {url}: {e}")
|
log.error(f"Failed to fetch {url}: {e}")
|
||||||
|
return
|
||||||
return io.BytesIO(b"")
|
|
||||||
|
|
||||||
|
|
||||||
async def process_event(url: str, url_num: int) -> str | None:
|
async def process_event(url: str, url_num: int) -> str | None:
|
||||||
|
|
@ -218,8 +217,7 @@ async def get_events(
|
||||||
|
|
||||||
window_start, window_end = now - timedelta(hours=1), now + timedelta(minutes=30)
|
window_start, window_end = now - timedelta(hours=1), now + timedelta(minutes=30)
|
||||||
|
|
||||||
buffer = await fetch_xml_stream(url, ssl_ctx)
|
if buffer := await fetch_xml_stream(url, ssl_ctx):
|
||||||
|
|
||||||
for _, elem in ET.iterparse(buffer, events=("end",)):
|
for _, elem in ET.iterparse(buffer, events=("end",)):
|
||||||
if elem.tag == "item":
|
if elem.tag == "item":
|
||||||
title = elem.findtext("title")
|
title = elem.findtext("title")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue