Compare commits
3
Commits
f31f0def29
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2db373f54a | ||
|
|
b7bf1d8c98 | ||
|
|
5b4c818451 |
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
FROM python:3.9
|
FROM python:3.11
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY ./install.sh ./requirements.txt ./
|
COPY ./install.sh ./requirements.txt ./
|
||||||
@@ -9,4 +9,4 @@ COPY ./core ./core
|
|||||||
ENTRYPOINT ["uvicorn", "--host", "0.0.0.0", "--port", "8000", "app.app:app"]
|
ENTRYPOINT ["uvicorn", "--host", "0.0.0.0", "--port", "8000", "app.app:app"]
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
ENV PYTHONUNBUFFERED=1
|
ENV PYTHONUNBUFFERED=1
|
||||||
|
|||||||
+18
-8
@@ -1,14 +1,19 @@
|
|||||||
import pprint
|
import pprint
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import List
|
from typing import List
|
||||||
from urllib.parse import quote
|
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from aiocache import cached, Cache
|
from aiocache import cached, Cache
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
_http = httpx.AsyncClient(timeout=20, follow_redirects=True)
|
_http = httpx.AsyncClient(
|
||||||
|
timeout=20,
|
||||||
|
follow_redirects=True,
|
||||||
|
headers={
|
||||||
|
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:98.0) Gecko/20100101 Firefox/98.0'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class PrayerTimes(BaseModel):
|
class PrayerTimes(BaseModel):
|
||||||
@@ -21,7 +26,7 @@ class PrayerTimes(BaseModel):
|
|||||||
isha: str
|
isha: str
|
||||||
|
|
||||||
|
|
||||||
@cached(ttl=3*60*60, cache=Cache.MEMORY)
|
@cached(ttl=3 * 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()
|
res.raise_for_status()
|
||||||
@@ -29,11 +34,16 @@ async def parse_prayer_times(url: str) -> List[PrayerTimes]:
|
|||||||
|
|
||||||
items = []
|
items = []
|
||||||
for row in soup.select('#tab-1 .vakit-table tbody tr'):
|
for row in soup.select('#tab-1 .vakit-table tbody tr'):
|
||||||
cell_texts = (c.text.strip() for c in row.select('td'))
|
cells = [c.text.strip() for c in row.select('td')]
|
||||||
headers = PrayerTimes.__fields__.keys()
|
items.append(PrayerTimes(
|
||||||
parsed = dict(zip(headers, cell_texts))
|
date=datetime.strptime(cells[0], '%d.%m.%Y'),
|
||||||
parsed['date'] = datetime.strptime(parsed['date'], '%d.%m.%Y')
|
fajr=cells[2],
|
||||||
items.append(PrayerTimes(**parsed))
|
sun=cells[3],
|
||||||
|
dhuhr=cells[4],
|
||||||
|
asr=cells[5],
|
||||||
|
maghrib=cells[6],
|
||||||
|
isha=cells[7],
|
||||||
|
))
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,5 +1,6 @@
|
|||||||
beautifulsoup4==4.10.0
|
beautifulsoup4==4.10.0
|
||||||
fastapi==0.74.1
|
fastapi==0.74.1
|
||||||
httpx==0.22.0
|
httpx==0.23.3
|
||||||
uvicorn==0.17.5
|
uvicorn==0.17.5
|
||||||
aiocache==0.11.1
|
aiocache==0.11.1
|
||||||
|
pydantic==1.10.7
|
||||||
|
|||||||
Reference in New Issue
Block a user