Reputation: 51
players
.:
):callsign:cid:realname:clienttype:frequency:latitude:longitude:altitude:groundspeed:planned_aircraft:planned_tascruise:planned_depairport:planned_altitude:planned_destairport:server:protrevision:rating:transponder:facilitytype:visualrange:planned_revision:planned_flighttype:planned_deptime:planned_actdeptime:planned_hrsenroute:planned_minenroute:planned_hrsfuel:planned_minfuel:planned_altairport:planned_remarks:planned_route:planned_depairport_lat:planned_depairport_lon:planned_destairport_lat:planned_destairport_lon:atis_message:time_last_atis_received:time_logon:heading:QNH_iHg:QNH_Mb:
That's how I read the HTML file:
import requests
link = "data.vatsim.net/vatsim-data.txt"
f = requests.get(link)
print(f.text)
Upvotes: 0
Views: 43
Reputation: 2132
Okey hi so this is the working code with explanation:
import requests
#Get the data
link = "http://data.vatsim.net/vatsim-data.txt"
f = requests.get(link)
players = str(f.text).split("!CLIENTS:")[1]
#Find what attributes we want to search for and store their idex inside 'attributes_to_find' dictionary as values
#ETA is not in the data! Couldn't find it.
attributes = "callsign:cid:realname:clienttype:frequency:latitude:longitude:altitude:groundspeed:planned_aircraft:planned_tascruise:planned_depairport:planned_altitude:planned_destairport:server:protrevision:rating:transponder:facilitytype:visualrange:planned_revision:planned_flighttype:planned_deptime:planned_actdeptime:planned_hrsenroute:planned_minenroute:planned_hrsfuel:planned_minfuel:planned_altairport:planned_remarks:planned_route:planned_depairport_lat:planned_depairport_lon:planned_destairport_lat:planned_destairport_lon:atis_message:time_last_atis_received:time_logon:heading:QNH_iHg:QNH_Mb:"
attributes = attributes.split(":")
attributes_to_find = {"callsign":0, "planned_route":0, "altitude":0}
for i, attribute in enumerate(attributes):
if attribute in attributes_to_find:
attributes_to_find[attribute] = i
#Function to find the player
def findPlayer(players, name = "None"):
players = players.split('\n')
for player in players: #Search all players
if name in player: #If name is in player data
for key, value in attributes_to_find.items(): #Search all attributes that we are looking for and print them
print("{}: '{}'".format(key, player.split(":")[value]))
return #If we found it return
findPlayer(players, "Carlos Marques LPPR")
This is the output of the code above:
callsign: 'UAE140'
planned_route: 'ANPUB1B ANPUB P627 GUTOX/N0495F340 P627 KADAP R348 LUXAG/N0485F360 R348 RUPIG UR348 TNV UB536 EROPA UT446 WIV WIV4A'
altitude: '36109'
I couldn't find the ETA attribute. But if you want to read any other attribute just add it to the attributes_to_find = {"callsign":0, "planned_route":0, "altitude":0}
dictionary.
Upvotes: 1