Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22fb2c9bc9 | ||
|
|
958fe4996c | ||
|
|
d29edccb21 |
+10
-8
@@ -3,10 +3,11 @@ from datetime import datetime
|
|||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
from aiocache import cached, Cache
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
_http = httpx.AsyncClient()
|
_http = httpx.AsyncClient(timeout=20, follow_redirects=True)
|
||||||
|
|
||||||
|
|
||||||
class PrayerTimes(BaseModel):
|
class PrayerTimes(BaseModel):
|
||||||
@@ -19,8 +20,10 @@ class PrayerTimes(BaseModel):
|
|||||||
isha: str
|
isha: str
|
||||||
|
|
||||||
|
|
||||||
|
@cached(ttl=60*60, cache=Cache.MEMORY)
|
||||||
async def parse_prayer_times(url: str) -> List[PrayerTimes]:
|
async def parse_prayer_times(url: str) -> List[PrayerTimes]:
|
||||||
res = await _http.get(url)
|
res = await _http.get(url)
|
||||||
|
res.raise_for_status()
|
||||||
soup = BeautifulSoup(res.text, 'html.parser')
|
soup = BeautifulSoup(res.text, 'html.parser')
|
||||||
|
|
||||||
items = []
|
items = []
|
||||||
@@ -117,16 +120,15 @@ async def _get_countries() -> dict:
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import asyncio
|
import asyncio
|
||||||
import core.diyanetdb
|
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
with core.diyanetdb.get_connection() as conn:
|
# with core.diyanetdb.get_connection() as conn:
|
||||||
id = core.diyanetdb.get_location_id(conn,
|
# id = core.diyanetdb.get_location_id(conn,
|
||||||
country_name='AVUSTURYA',
|
# country_name='AVUSTURYA',
|
||||||
city_name='PESSENDELLACH')
|
# city_name='PESSENDELLACH')
|
||||||
url = make_location_url(id)
|
# url = make_location_url(id)
|
||||||
times = await parse_prayer_times(url)
|
times = await parse_prayer_times('https://namazvakitleri.diyanet.gov.tr/en-US')
|
||||||
print(times)
|
print(times)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -7,7 +7,7 @@ from pydantic import BaseModel
|
|||||||
|
|
||||||
from app import config
|
from app import config
|
||||||
|
|
||||||
_http = httpx.AsyncClient()
|
_http = httpx.AsyncClient(timeout=20, follow_redirects=True)
|
||||||
|
|
||||||
|
|
||||||
class Location(BaseModel):
|
class Location(BaseModel):
|
||||||
|
|||||||
+6
-5
@@ -1,5 +1,6 @@
|
|||||||
bs4==0.0.1
|
beautifulsoup4==4.10.0
|
||||||
fastapi==0.47.1
|
fastapi==0.74.1
|
||||||
httpx==0.11.1
|
httpx==0.22.0
|
||||||
loguru==0.4.1
|
loguru==0.6.0
|
||||||
uvicorn==0.11.1
|
uvicorn==0.17.5
|
||||||
|
aiocache==0.11.1
|
||||||
Reference in New Issue
Block a user