Repository navigation
Expand file tree
/
Copy pathamsas.py
More file actions
89 lines (57 loc) · 2.4 KB
/
Copy pathamsas.py
File metadata and controls
89 lines (57 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pandas as pd
def main():
print ('Welcome to AMSASpy. Your at home AMSAS!')
print ('\n')
print ('Use as you would use AMSAS but enter q to exit the program!')
print ('\n')
while True:
site = input('>> ').upper()
print ('\n')
if site == 'Q':
break
if len(site) == 3:
canadian = 'C' + site
american = 'K' + site
#check the site
xc = check(canadian)
xk = check(american)
if xc == True:
address = 'http://weather.rap.ucar.edu/surface/index.php?metarIds='+canadian+'&hoursStr=past+12+hours&std_trans=standard&num_metars=number&submit_metars=Retrieve'
site = canadian
elif xk == True:
address = 'http://weather.rap.ucar.edu/surface/index.php?metarIds='+american+'&hoursStr=past+12+hours&std_trans=standard&num_metars=number&submit_metars=Retrieve'
site = american
else:
address = False
else:
canadian = check(site)
american = check(site)
if canadian == True:
address = 'http://weather.rap.ucar.edu/surface/index.php?metarIds='+site+'&hoursStr=past+12+hours&std_trans=standard&num_metars=number&submit_metars=Retrieve'
elif american == True:
address = 'http://weather.rap.ucar.edu/surface/index.php?metarIds='+site+'&hoursStr=past+12+hours&std_trans=standard&num_metars=number&submit_metars=Retrieve'
else:
address = False
# address, site = getCanadian_site(site)
if address == False:
print ('Site does not exist in NCAR database. Try another site.')
else:
metar_raw = pd.read_html(address)[0]
metar = metar_raw[0][1].split(site)
del metar[0]
for i in reversed(metar):
print (site + i)
print ('\n')
#---------------------------FUNCTIONS------------------------------------------
def check(site):
"""
Check to see if the site exists.
"""
address = 'http://weather.rap.ucar.edu/surface/index.php?metarIds='+site+'&hoursStr=past+12+hours&std_trans=standard&num_metars=number&submit_metars=Retrieve'
metar_raw = pd.read_html(address)[0]
if len(metar_raw) == 1:
checker = False
else:
checker = True
return checker
main()