Advertisement
storca897654

metar-taf-avwx-python

Apr 18th, 2021
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #!/usr/bin/python3.8
  2. import requests as r
  3. import sys
  4.  
  5. headers = {
  6.   'Authorization': 'your-super-token-that-you-got-on-account.avwx.rest'
  7. }
  8. #response = r.get('https://avwx.rest/api/metar/LSGG', headers=headers)
  9.  
  10. #response_body = urlopen(request).read()
  11. #print(response_body)
  12.  
  13. #print(response.json()["raw"])
  14.  
  15. def printmetartaf(icao_l):
  16.     icao = icao_l.upper()
  17.     print("%s's weather" % icao)
  18.     metar = r.get('https://avwx.rest/api/metar/%s' % icao, headers=headers)
  19.     if metar.status_code == 204:
  20.         print("METAR unavailable for %s" % icao)
  21.     elif metar.status_code == 400:
  22.         print("I don't think \"%s\" is an airport mate" % icao)
  23.         return
  24.     else:
  25.         print("METAR : %s" % metar.json()["raw"])
  26.     taf = r.get('https://avwx.rest/api/taf/%s' % icao, headers=headers)
  27.     if taf.status_code == 204:
  28.         print("TAR unavailable for %s" % icao)
  29.     else:
  30.         print("TAF : %s" % taf.json()["raw"])
  31.  
  32. for arg in sys.argv[1:]:
  33.     printmetartaf(arg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement