diff --git a/jnfilter/__init__.py b/jnfilter/__init__.py
index 2c7641a07a789f2d4b170076174701443c1670e2..35be6bd4c97fbe3e44b81d07c076bb3662780ae4 100644
--- a/jnfilter/__init__.py
+++ b/jnfilter/__init__.py
@@ -1,15 +1,13 @@
import re
import httpx
-import uvicorn
from functools import reduce
from typing import List, Iterator, Union
from xml.etree.ElementTree import ElementTree, fromstring, tostring, register_namespace
-from fastapi import FastAPI
-from starlette.responses import Response, PlainTextResponse
+from flask import Flask, Response, request
-app = FastAPI()
+app = Flask(__name__)
URL = "https://jovemnerd.com.br/feed-nerdcast/"
@@ -32,9 +30,6 @@ register_namespace("googleplay", GOOGLEPLAY)
register_namespace("itunes", ITUNES)
register_namespace("atom", ATOM)
-
-class XMLResponse(Response):
- media_type = "application/xml"
def match(title: str, series: List[str]) -> bool:
@@ -74,36 +69,34 @@ for item in tree_root.findall("./channel/item"):
yield item.find("title").text
-async def load_and_filter(series: str, tag: Union[bool, None] = False) -> str:
+def load_and_filter(series: str, tag: Union[bool, None] = False) -> str:
series = series or 'nerdcast'
series = series.split(',')
- async with httpx.AsyncClient() as client:
- response = await client.get(URL)
+ with httpx.Client() as client:
+ response =client.get(URL)
xml_str = response.content
return filter_xml(xml_str, series, tag)
-async def load_titles() -> Iterator[str]:
- async with httpx.AsyncClient() as client:
- response = await client.get(URL)
+def load_titles() -> Iterator[str]:
+ with httpx.Client() as client:
+ response = client.get(URL)
xml_str = response.content
return filter_titles_xml(xml_str)
-@app.head("/")
-@app.get("/", response_class=XMLResponse)
-async def root(q: str = '', tag: Union[bool, None] = False):
- return await load_and_filter(q, tag)
+@app.route("/", methods=['GET', 'HEAD'])
+def root(q: str = '', tag: Union[bool, None] = False):
+ q = request.args.get("q", "")
+ tag = request.args.get("tag", False)
+ return load_and_filter(q, tag), 200, {'Content-Type': 'application/xml'}
-@app.get("/titles", response_class=PlainTextResponse)
-async def titles():
- titles = await load_titles()
+@app.route("/titles", methods=['GET'])
+def titles():
+ titles = load_titles()
return "\n".join(titles)
-@app.get("/series")
-async def titles():
+@app.route("/series", methods=['GET'])
+def series():
return [i[0] for i in RegexCollection.items()]
-
-def run():
- uvicorn.run(app=app, host="0.0.0.0", port=32000)
diff --git a/setup.py b/setup.py
index 07add8246257827906a2d7f0a149d2a00ff2223d..7692d27d74355ce026d0fc38d5e9febdd85f2026 100644
--- a/setup.py
+++ b/setup.py
@@ -2,8 +2,7 @@ from setuptools import setup
requirements = [
'httpx==0.21.1',
- 'fastapi==0.70.0',
- 'uvicorn==0.15.0'
+ 'flask==2.2.2',
]