Lab 5

The Problem

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 (

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:

  1. readable site name
  2. average gage height
  3. 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.


The easiest path to getting the most points might be:

  1. Check out the USGS site and see how to generate a url to grab data
  2. Read the man page of libcurl
  3. Write a basic libcurl program to fetch a url and print to the console
  4. Modify your libcurl program to work with HTTPS
  5. Use a USGS url and see how the RDB format works
  6. Modify your program to handle the data instead of printing
  7. Extract the site names
  8. Summarize the data by site
  9. Print out site names and summarized data
  10. Read a file with site codes
  11. Generate the url from the sites
  12. Get an A

This is not your friend’s work. This is not the internet’s work. This is your work...


Submit your code using the handin script, handin cmsc242 lab5 your_directory_name.
You will need to be in the directory which contains your_directory_name.

If you would like your lab grade by Apr. 24th, you can submit your lab before Apr. 23rd at noon.

Otherwise, the lab is due at 11:59pm Apr. 27th 2020.