Skip to content

Instantly share code, notes, and snippets.

@greencoder
Last active July 7, 2017 19:52
Show Gist options
  • Save greencoder/0fc4b73b9ebd79de8ca491e6ab8c24be to your computer and use it in GitHub Desktop.
Save greencoder/0fc4b73b9ebd79de8ca491e6ab8c24be to your computer and use it in GitHub Desktop.
Fetching Historical Observations from ACIS (Using either curl or Python)
import argparse
import json
import re
import sys
import urllib2
# Parse the command-line arguments
argparser = argparse.ArgumentParser()
argparser.add_argument('date_start', help='Start Date')
argparser.add_argument('date_end', help='End Date')
argparser.add_argument('station')
args = argparser.parse_args()
# Validate the start date
if args.date_start != 'por':
if not re.search(r'\d{4}-\d{2}-\d{2}', args.date_start):
sys.exit('Invalid start date: %s' % args.date_start)
# Validate the end date
if args.date_end != 'por':
if not re.search(r'\d{4}-\d{2}-\d{2}', args.date_end):
sys.exit('Invalid end date: %s' % args.date_end)
# Create the request body
params = {
'sid': args.station,
'sdate': args.date_start,
'edate': args.date_end,
'output': 'csv',
'elems': [
{'name': 'maxt', 'add': 't'},
{'name': 'mint', 'add': 't'},
{'name': 'avgt', 'add': 't'},
{'name': 'pcpn', 'add': 't'},
{'name': 'snow', 'add': 't'},
{'name': 'snwd', 'add': 't'},
{'name': 'hdd', 'add': 't'},
{'name': 'cdd', 'add': 't'},
]
}
url = 'http://data.rcc-acis.org/StnData'
body = {'params': json.dumps(params)}
request = urllib2.urlopen(url, data=body)
response = request.read()
print response
curl 'http://data.rcc-acis.org/StnData' \
--data 'params={"sid":"denthr","sdate":"por","edate":"por","elems":"maxt,mint,avgt,pcpn,snow,snwd,hdd,cdd","output":"csv"}' \
> denthr.csv
date maxt mint avgt pcpn snow snwd hdd cdd
2017-06-27 97 59 78.0 T 0.0 0 0 13
2017-06-28 90 52 71.0 T 0.0 0 0 6
2017-06-29 87 54 70.5 0.13 0.0 0 0 6
2017-06-30 74 52 63.0 0.08 0.0 0 2 0
2017-07-01 89 51 70.0 0.00 0.0 0 0 5
2017-07-02 94 58 76.0 0.00 0.0 0 0 11
2017-07-03 92 53 72.5 0.00 0.0 0 0 8
2017-07-04 95 61 78.0 0.00 0.0 0 0 13
2017-07-05 98 62 80.0 0.00 0.0 0 0 15
2017-07-06 100 67 83.5 T 0.0 0 0 19
2017-07-07 M M M 0.00 M M M M
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@greencoder
Copy link
Author

This is the raw data behind the NOAA "NowData" project.

The web services are documented here You can also use this query builder to figure out how it all works.

I'm not sure if it's documented, but por is the shorthand for period of record and gets you the data going as far back as it exists for a station.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment