You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.0 KiB
Python

from datetime import datetime
from typing import List
import httpx
from bs4 import BeautifulSoup
from pydantic import BaseModel
_http = httpx.AsyncClient()
class PrayerTimes(BaseModel):
date: datetime
fajr: str
sun: str
dhuhr: str
asr: str
maghrib: str
isha: str
async def parse_prayer_times(url: str) -> List[PrayerTimes]:
res = await _http.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
items = []
for row in soup.select('#tab-1 .vakit-table tbody tr'):
cell_texts = (c.text.strip() for c in row.select('td'))
headers = PrayerTimes.__fields__.keys()
parsed = dict(zip(headers, cell_texts))
parsed['date'] = datetime.strptime(parsed['date'], '%d.%m.%Y')
items.append(PrayerTimes(**parsed))
return items
if __name__ == '__main__':
import asyncio
import pprint
loop = asyncio.get_event_loop()
results = loop.run_until_complete(parse_prayer_times('https://namazvakitleri.diyanet.gov.tr/en-US'))
pprint.pprint(results)