.gitignore + safety header

This commit is contained in:
Debucquoy Anthony 2022-08-28 16:26:50 +02:00
parent 33cf0cf461
commit ac23c63ae5
Signed by: tonitch
GPG Key ID: A78D6421F083D42E
2 changed files with 5 additions and 2 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
env/

View File

@ -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 ❎ ")