File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import requests
2+
3+ # Dynamically retrieve the list of online BNLS servers from BNETDocs:
4+ url = 'https://bnetdocs.org/servers.json?type_id=20&status=1'
5+
6+ try :
7+ # Send GET request to retrieve server list
8+ response = requests .get (url )
9+ response .raise_for_status () # Raise error for bad status codes
10+
11+ # Check if the response content type starts with 'application/json'
12+ content_type = response .headers .get ('Content-Type' , '' )
13+ if not content_type .startswith ('application/json' ):
14+ raise ValueError (f"Unexpected MIME type: { content_type } " )
15+
16+ # Parse JSON data
17+ json_data = response .json ()
18+
19+ except requests .exceptions .RequestException as e :
20+ print (f'Failed to download server list from: { url } \n Error: { e } ' )
21+ except ValueError as ve :
22+ print (f'Error processing data: { ve } ' )
23+ else :
24+ # Add a blank line (based on original PHP script behavior)
25+ print ()
26+
27+ # Print server addresses
28+ for server in json_data .get ('servers' , []):
29+ print (server ['address' ])
30+
You can’t perform that action at this time.
0 commit comments