add download_drug
This commit is contained in:
parent
ba9e90cd60
commit
4a45b007c0
1 changed files with 13 additions and 0 deletions
13
src/cache/drug_cache.py
vendored
13
src/cache/drug_cache.py
vendored
|
|
@ -37,6 +37,19 @@ async def convert_drug_result(drug: DrugPriceResponse) -> list[DrugFull]:
|
|||
return [DrugFull.model_validate(r) for r in response_dict["result"]]
|
||||
|
||||
|
||||
async def download_drug(drug_name: str):
|
||||
with Session() as session:
|
||||
drugs = session.query(Drug).filter(Drug.name == drug_name).all()
|
||||
if drugs:
|
||||
return
|
||||
|
||||
parser = DrugPriceParser()
|
||||
result = parser.get_drug_prices(drug_name)
|
||||
drugs = await convert_drug_result(result)
|
||||
|
||||
await store_drug(drugs)
|
||||
|
||||
|
||||
async def get_drug(drug_name: str) -> list[DrugFull]:
|
||||
parser = DrugPriceParser()
|
||||
result = parser.get_drug_prices(drug_name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue