diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdaab25 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +env/ diff --git a/main.py b/main.py index 545f9cc..89b3d0f 100644 --- a/main.py +++ b/main.py @@ -27,6 +27,8 @@ async def main(): async def fetch_station(station: str, session: aiohttp.ClientSession, trains: list) -> None: train_list = [] url = "http://www.belgianrail.be/jp/nmbs-realtime/stboard.exe/en" + url_header = {'User-Agent': 'python script to fetch trains of belgium. (d.tonitch@gmail.com - in case it is a problem)', + 'From': 'd.tonitch@gmail.com'} url_data = { 'realtime': 'Show', # Dunno 'sqQueryPageDisplayed': 'yes', # Dunno @@ -43,7 +45,7 @@ async def fetch_station(station: str, session: aiohttp.ClientSession, trains: li 'start': 'Show' # Dunno } try: - async with session.post(url, data=url_data) as resp: + async with session.post(url, data=url_data, headers=url_header) as resp: if resp.status == 200: print(f"station {station} success ✅") soup = BeautifulSoup(await resp.text(), 'html.parser') @@ -52,7 +54,7 @@ async def fetch_station(station: str, session: aiohttp.ClientSession, trains: li train_list = [''.join(i.a.contents) for i in products] for train in train_list: if train not in trains and train: - trains.append(re.sub(" +", " ",train.strip())) + trains.append(re.sub(" +", " ", train.strip())) return None except aiohttp.client_exceptions.ServerDisconnectedError: print(f"station {station} failed ❎ ")