Last active
July 29, 2021 18:33
-
-
Save akkana/4785bb0d72fa7e4492b57e0f7ccee070 to your computer and use it in GitHub Desktop.
Test of downloading data from the Weather Machine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import requests | |
request_keys = [ 'spd1', 'spd2', 'spd3', # Speeds at 12, 23 and 46 m height | |
'sdspd1', 'sdspd2', 'sdspd3', # sdev of wind speeds | |
'dir1', 'dir2', 'dir3', # wind directions 12, 23, 46 m | |
'sddir1', 'sddir2', 'sddir3', # sdev of wind directions | |
'w1', 'w2', 'w3', # vertical wind speeds | |
'sdw1', 'sdw2', 'sdw3', # stdev of vertical wind sp | |
'fvel2', # friction velocity | |
'temp0', 'temp1', 'temp2', 'temp3', # temps 1.2, 12, 23, 46 | |
'press', # pressure | |
'rh', 'ah', # rel and abs humidity | |
'dewp', 'precip', # dew point, precipitation | |
'swdn', 'swup', # shortwave radiation down/up | |
'lwdn', 'lwup', # longwave radiation down/up | |
'netrad', # net radiation | |
'sheat', 'lheat', # sensible/latent heatflux | |
'stemp1', 'stemp2', 'stemp3',# soil temp -.02, -.06, -.10 m | |
'smoist1', 'smoist2', # soil moisture 0 to 0.8, 0 to -.15 | |
'gheat' # ground heat flux | |
] | |
request_data = [ | |
('tower', 'ta53'), | |
('format', 'tab'), | |
('type', '15'), | |
('access', 'extend'), | |
('SUBMIT_SIGNALS', 'Download Data'), | |
('startyear', '2021'), | |
('startmonth', '07'), | |
('startday', '01'), | |
('starthour', '00'), | |
('startminute', '00'), | |
('endyear', '2021'), | |
('endmonth', '07'), | |
('endday', '14'), | |
('endhour', '23'), | |
('endminute', '45') | |
] | |
for key in request_keys: | |
request_data.append(('checkbox', key)) | |
# LANL_URL = 'https://www.weather.lanl.gov/data_request_green_weather.asp' | |
# LANL_URL = 'http://www.weather.lanl.gov/data_request_green_weather.asp' | |
# LANL_URL = 'https://weathermachine.lanl.gov/data_request_green_weather.asp' | |
LANL_URL = 'http://weathermachine.lanl.gov/data_request_green_weather.asp' | |
headers = { | |
'User-Agent': 'LANL Weather Fetcher 0.9', | |
'Referer': LANL_URL, | |
'Content-Type': 'application/x-www-form-urlencoded', | |
} | |
print("Headers:", headers) | |
print("Request data:", request_data) | |
r = requests.post(LANL_URL, | |
headers=headers, | |
data=request_data, verify=False) | |
print("Received", len(r.text), "characters") | |
if len(r.text) > 0: | |
outfilename = "fetched.html" | |
with open(outfilename, "w") as outfp: | |
outfp.write(r.text) | |
print("Wrote", outfilename) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment