A common way of retrieving data from the internet is through the use of REST style HTTP requests. The USGS provides REST api for retrieving instantaneous values for water level data (https://waterservices.usgs.gov/rest/).
We will retrieve instantaneous values water depth data for multiple sites and process the returned values. Although we could
write our code using Sockets, we will use the curl library (libcurl
). The curl library
works seamlessly with the HTTPS protocol that the USGS uses.
Your program should read an input file, taken as a command line argument, listing USGS codes, one per line, to fetch data. You should retrieve the last two hours of readings. For each site print to the console:
- readable site name
- average gage height
- the trend -- (increasing, decreasing, level, crest, valley)
You will need to decide the threshold for being level. A crest event is the peak height of a flood (increasing then decreasing). A valley event is the low point (decreasing then increasing). Your trend should be prettified with some ANSI escape code glitter.
PLEASE DON'T SPAM THE USGS WITH REQUESTS wait 30 seconds or so between requests.