-
Notifications
You must be signed in to change notification settings - Fork 0
/
buscar_lista_termos.py
37 lines (27 loc) · 1.08 KB
/
buscar_lista_termos.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from requests import get as req_get
from json import loads as json_load
from json import dumps as json_dump
def api_uri(page: int) -> str:
return f'https://www.tabnews.com.br/api/v1/contents?strategy=new&page={page}'
def buscar_lista_termos(lista_termos: list[str], limite: int) -> None:
with open('buscar_lista_termos.json', 'w') as file:
resultado = []
page = 1
while True:
temp = req_get(api_uri(page))
res: list[dict] = json_load(temp.text)
tem_todos_os_termos: bool = True
for item in res:
titulo: str = item['title'].lower()
for termo in lista_termos:
if (titulo.find(termo.lower()) == -1):
tem_todos_os_termos = False
continue
if (tem_todos_os_termos == False):
continue
resultado.append(item)
print(titulo)
if (res == [] or len(resultado) >= limite):
break
page += 1
file.write(json_dump(resultado))