-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(API): Implemented function that build the Cutter Table dictionary.
Was implemented a function that makes a request to a UFRRJ Library website and with Beautifulsoup4 library build a dictionary with Cutter Table. This function is called on start fastaAPI project and this dictionary stay cached in memory all the time. Closes #9
- Loading branch information
1 parent
2414ebf
commit 42e7b2c
Showing
6 changed files
with
51 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length = 120 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import httpx | ||
from bs4 import BeautifulSoup | ||
|
||
|
||
def gen_cutter_table(): | ||
cutter_table = {} | ||
for index in range(1, 10): | ||
url = f'https://academico.ufrrj.br/biblioteca/cutter/cutter{index}.html' | ||
|
||
resp = httpx.get(url) | ||
|
||
soup = BeautifulSoup(resp.text, 'html.parser') | ||
|
||
letters = soup.find_all('b')[0].getText() | ||
|
||
for i, letter in enumerate(letters): | ||
cutter_table[letter.lower()] = [] | ||
for element in soup.find_all('pre')[i].getText().split('\n'): | ||
if element.strip() and element.strip().isascii(): | ||
code, abreviaton = element.strip().split(' ' * 5) | ||
cutter_table[letter.lower()].append((code, abreviaton.lower())) | ||
|
||
return cutter_table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
from fastapi import FastAPI | ||
|
||
from api.business_rules.cutter_table import gen_cutter_table | ||
|
||
api = FastAPI() | ||
|
||
cutter_table = {} | ||
|
||
|
||
@api.on_event("startup") | ||
async def startup_event(): | ||
global cutter_table | ||
cutter_table = gen_cutter_table() | ||
|
||
|
||
@api.get('/health') | ||
def health(): | ||
async def health(): | ||
return {'message': 'The API is 100% ok!'} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters