.gitignore + safety header
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
				
			|||||||
 | 
					env/
 | 
				
			||||||
							
								
								
									
										4
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								main.py
									
									
									
									
									
								
							@ -27,6 +27,8 @@ async def main():
 | 
				
			|||||||
async def fetch_station(station: str, session: aiohttp.ClientSession, trains: list) -> None:
 | 
					async def fetch_station(station: str, session: aiohttp.ClientSession, trains: list) -> None:
 | 
				
			||||||
    train_list = []
 | 
					    train_list = []
 | 
				
			||||||
    url = "http://www.belgianrail.be/jp/nmbs-realtime/stboard.exe/en"
 | 
					    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 = {
 | 
					    url_data = {
 | 
				
			||||||
        'realtime': 'Show',  # Dunno
 | 
					        'realtime': 'Show',  # Dunno
 | 
				
			||||||
        'sqQueryPageDisplayed': 'yes',  # Dunno
 | 
					        'sqQueryPageDisplayed': 'yes',  # Dunno
 | 
				
			||||||
@ -43,7 +45,7 @@ async def fetch_station(station: str, session: aiohttp.ClientSession, trains: li
 | 
				
			|||||||
        'start': 'Show'  # Dunno
 | 
					        'start': 'Show'  # Dunno
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    try:
 | 
					    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:
 | 
					            if resp.status == 200:
 | 
				
			||||||
                print(f"station {station} success ✅")
 | 
					                print(f"station {station} success ✅")
 | 
				
			||||||
            soup = BeautifulSoup(await resp.text(), 'html.parser')
 | 
					            soup = BeautifulSoup(await resp.text(), 'html.parser')
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user