parent
7ccb02d9c5
commit
0a39c4dbbe
2 changed files with 75 additions and 4 deletions
|
|
@ -7,6 +7,8 @@ from time import time
|
|||
|
||||
import requests
|
||||
|
||||
url = "https://www.gwr.com/your-tickets/choosing-your-ticket/advance-tickets"
|
||||
|
||||
|
||||
def extract_weekday_date(html: str) -> date | None:
|
||||
"""Furthest date of GWR advance ticket booking."""
|
||||
|
|
@ -30,13 +32,12 @@ def extract_weekday_date(html: str) -> date | None:
|
|||
def advance_tickets_page_html(data_dir: str, ttl: int = 60 * 60 * 6) -> str:
|
||||
"""Get advance-tickets web page HTML with cache."""
|
||||
filename = os.path.join(data_dir, "advance-tickets.html")
|
||||
url = "https://www.gwr.com/your-tickets/choosing-your-ticket/advance-tickets"
|
||||
mtime = os.path.getmtime(filename) if os.path.exists(filename) else 0
|
||||
if (time() - mtime) < ttl: # use cache
|
||||
return open(filename).read()
|
||||
r = requests.get(url)
|
||||
open(filename, "w").write(r.text)
|
||||
return r.text
|
||||
html = requests.get(url).text
|
||||
open(filename, "w").write(html)
|
||||
return html
|
||||
|
||||
|
||||
def advance_ticket_date(data_dir: str) -> date | None:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue