From 22fb2c9bc9fea50f0b2934c16b7299012f9ba57a Mon Sep 17 00:00:00 2001 From: Abdussamet Kocak Date: Sun, 27 Feb 2022 15:43:34 +0300 Subject: [PATCH] fix: Add in-memory cache --- core/diyanet.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/diyanet.py b/core/diyanet.py index 6e73f2f..110f977 100644 --- a/core/diyanet.py +++ b/core/diyanet.py @@ -3,6 +3,7 @@ from datetime import datetime from typing import List import httpx +from aiocache import cached, Cache from bs4 import BeautifulSoup from pydantic import BaseModel @@ -19,8 +20,10 @@ class PrayerTimes(BaseModel): isha: str +@cached(ttl=60*60, cache=Cache.MEMORY) async def parse_prayer_times(url: str) -> List[PrayerTimes]: res = await _http.get(url) + res.raise_for_status() soup = BeautifulSoup(res.text, 'html.parser') items = [] @@ -117,16 +120,15 @@ async def _get_countries() -> dict: if __name__ == '__main__': import asyncio - import core.diyanetdb async def main(): - with core.diyanetdb.get_connection() as conn: - id = core.diyanetdb.get_location_id(conn, - country_name='AVUSTURYA', - city_name='PESSENDELLACH') - url = make_location_url(id) - times = await parse_prayer_times(url) + # with core.diyanetdb.get_connection() as conn: + # id = core.diyanetdb.get_location_id(conn, + # country_name='AVUSTURYA', + # city_name='PESSENDELLACH') + # url = make_location_url(id) + times = await parse_prayer_times('https://namazvakitleri.diyanet.gov.tr/en-US') print(times)