jnfilter @ 74aa2ec7fcd8881b442dce1e6cd24e53ee1c2919

feat: Adiciona tag opcionalmente

Agora para ativar a tag no metadata e preciso passar um _query param_
`tag=true`.
  1diff --git a/LICENSE b/LICENSE
  2new file mode 100644
  3index 0000000000000000000000000000000000000000..588d327cb48b7636ddc55620254b780856f2e4bd
  4--- /dev/null
  5+++ b/LICENSE
  6@@ -0,0 +1,22 @@
  7+MIT License
  8+
  9+Copyright (c) 2021 Gabriel Arakaki Giovanini
 10+
 11+Permission is hereby granted, free of charge, to any person obtaining a copy of
 12+this software and associated documentation files (the "Software"), to deal in
 13+the Software without restriction, including without limitation the rights to
 14+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 15+of the Software, and to permit persons to whom the Software is furnished to do
 16+so, subject to the following conditions:
 17+
 18+The above copyright notice and this permission notice (including the next
 19+        paragraph) shall be included in all copies or substantial portions of the
 20+Software.
 21+
 22+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 23+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 24+    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 25+    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 26+    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 27+    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 28+    SOFTWARE.
 29diff --git a/README.md b/README.md
 30index 71a700f3f7bd664861b2e9e9917cf3d1d6ddfc48..30a5a41f93c90024e19188169332f1920655b944 100644
 31--- a/README.md
 32+++ b/README.md
 33@@ -45,21 +45,26 @@ Adicionei recentemente uma parte no código pare mexer na metadata do feed
 34 (mudar titulo, nome, descrição, etc) para fazer com que o Pocketcast reconheça
 35 o feed gerado como se fosse outro feed. Eles usam a metadata para decidir se um
 36 feed e novo, então como eu não mexia na metadata ele gerava um link para o feed
 37-original do jovem nerd.
 38+original do jovem nerd. Para ativar essa funcionalidade use parametro
 39+`tag=true`, exemplo:
 40+
 41+```
 42+https://jnfilter.gabrielgio.me/?q=nerdcash,nerdcast&tag=true
 43+```
 44 
 45 Entao os usuarios do Pocketcast tem que ir ao https://pocketcasts.com/submit/
 46 para submeterem a sua URL. Observação, esse processo de submit deles e meio
 47 cagado, então se ele não oferecer o feed certo tente trocar as ordens dos
 48 parâmetro, se tiver `nerdcast,mamicas` troque para `mamicas,nercast`
 49 
 50-o ideal e que cliente de podcast nao obrigue a fazer isso mas fazer o que as outras
 51-opções fazem pior.
 52+o ideal e que cliente de podcast nao obrigue a fazer isso mas fazer o que as
 53+outras opções fazem pior.
 54 
 55 ## Para programadores
 56 
 57-E um projeto simples feito em cima do FastApi. Ele vai pegar o _feed_ e
 58-filtrar os itens do _feed_ do podcast. Não tem cache nem nada sendo armazenado,
 59-todo processamento e feito a partir do feed para cada requisição.
 60+E um projeto simples feito em cima do FastApi. Ele vai pegar o _feed_ e filtrar
 61+os itens do _feed_ do podcast. Não tem cache nem nada sendo armazenado, todo
 62+processamento e feito a partir do feed para cada requisição.
 63 
 64 Para rodar basta instalar os requirements e rodar o seguinte código:
 65 
 66diff --git a/jnfilter/__main__.py b/jnfilter/__main__.py
 67new file mode 100644
 68index 0000000000000000000000000000000000000000..ff2b876b8a6e8561b7cf4bcd07153c57cf6527da
 69--- /dev/null
 70+++ b/jnfilter/__main__.py
 71@@ -0,0 +1,4 @@
 72+from . import run
 73+
 74+if __name__ == '__main__':
 75+    run()
 76diff --git a/jnfilter/main.py b/jnfilter/__init__.py
 77rename from jnfilter/main.py
 78rename to jnfilter/__init__.py
 79index 193975fb757caa8556d9e68f6a8e0c759b3af8bc..2c7641a07a789f2d4b170076174701443c1670e2 100644
 80--- a/jnfilter/main.py
 81+++ b/jnfilter/__init__.py
 82@@ -3,7 +3,7 @@ import httpx
 83 import uvicorn
 84 
 85 from functools import reduce
 86-from typing import List, Iterator
 87+from typing import List, Iterator, Union
 88 from xml.etree.ElementTree import ElementTree, fromstring, tostring, register_namespace
 89 from fastapi import FastAPI
 90 from starlette.responses import Response, PlainTextResponse
 91@@ -44,21 +44,20 @@
 92     return reduce(lambda x, y: x or _match(y), series, False)
 93 
 94 
 95-def filter_xml(xml_str: str, series: List[str]) -> str:
 96+def filter_xml(xml_str: str, series: List[str], tag: Union[bool, None] = False) -> str:
 97     tree = ElementTree(fromstring(xml_str))
 98     tree_root = tree.getroot()
 99     for channel in tree_root.findall("./channel"):
100-        tag = f' [{",".join(series)}]'.upper()
101 
102-        channel.find("title").text += tag
103-        channel.find("description").text += tag
104-        channel.find("link").text += f"?{tag}"
105-        channel.find(f"{{{ITUNES}}}author").text += tag
106-        channel.find(f"{{{GOOGLEPLAY}}}author").text += tag
107-        channel.find(f"{{{ITUNES}}}subtitle").text += tag
108-        channel.find(f"{{{ITUNES}}}summary").text += tag
109-
110-        print({elem.tag for elem in channel.iter()})
111+        if tag:
112+            tag = f' [{",".join(series)}]'.upper()
113+            channel.find("title").text += tag
114+            channel.find("description").text += tag
115+            channel.find("link").text += f"?{tag}"
116+            channel.find(f"{{{ITUNES}}}author").text += tag
117+            channel.find(f"{{{GOOGLEPLAY}}}author").text += tag
118+            channel.find(f"{{{ITUNES}}}subtitle").text += tag
119+            channel.find(f"{{{ITUNES}}}summary").text += tag
120 
121         for item in channel.findall("item"):
122             title = item.find("title").text
123@@ -75,13 +74,13 @@     for item in tree_root.findall("./channel/item"):
124         yield item.find("title").text
125 
126 
127-async def load_and_filter(series: str) -> str:
128+async def load_and_filter(series: str, tag: Union[bool, None] = False) -> str:
129     series = series or 'nerdcast'
130     series = series.split(',')
131     async with httpx.AsyncClient() as client:
132         response = await client.get(URL)
133         xml_str = response.content
134-        return filter_xml(xml_str, series)
135+        return filter_xml(xml_str, series, tag)
136 
137 
138 async def load_titles() -> Iterator[str]:
139@@ -92,8 +91,8 @@         return filter_titles_xml(xml_str)
140 
141 @app.head("/")
142 @app.get("/", response_class=XMLResponse)
143-async def root(q: str = ''):
144-    return await load_and_filter(q)
145+async def root(q: str = '', tag: Union[bool, None] = False):
146+    return await load_and_filter(q, tag)
147 
148 
149 @app.get("/titles", response_class=PlainTextResponse)
150diff --git a/setup.py b/setup.py
151index 8f95a75c9c6878bc492bd789794aa4ffa918dd1f..07add8246257827906a2d7f0a149d2a00ff2223d 100644
152--- a/setup.py
153+++ b/setup.py
154@@ -8,16 +8,17 @@ ]
155 
156 
157 setup(name='jnfilter',
158-    version='0.2.1',
159+    version='0.3.0',
160     description='A FastAPI server to filter Nercast podcast feed',
161     url='https://git.sr.ht/~gabrielgio/jnfilter',
162     author='Gabriel Arakaki Giovanini',
163     author_email='mail@gabrielgio.me',
164     license='MIT',
165     packages=['jnfilter'],
166-    entry_points="""
167-    [console_scripts]
168-    jnfilterd=jnfilter.main:run
169-    """,
170+    entry_points={
171+        'console_scripts': [
172+            'jnfilterd=jnfilter',
173+        ]
174+    },
175     install_requires=requirements,
176     zip_safe=False)