Teacher's Choice

Need An Umbrella? (Teacher's Choice)

In this activity, you'll build an UMBRELLA? block predicate that tells you if you'll need an umbrella today.

But wait, doesn't this block need an input to say where you are? Nope: your IP address contains information about your location!

  1. Determine your computer's IP address.
    Perhaps you already have a block that finds your IP address?
  2. Edit the following URL, replacing the IP address with your own: http://ipinfo.io/72.229.28.185. What information does that page give you?
  3. Use Snap! to retrieve the information from that web page, using the proxied http block:Getting info about your IP
  4. Some of the information might have slight inaccuracies. IP addresses often give the location of an Internet service provider, usually from a nearby location.

The amount of detailed information available from an IP address is pretty amazing (and a little scary), especially when you think about the ways that information can be used.

Screen shot of ipinfo.io

PG: I looked first for a "details" link or tab, then tried the developers link in response to "read the details on ipinfo.io..." Not finding /loc, I almost gave up. OH! That's the info we're getting in "Try the JSON API from the command line." That is far from obvious, since the student at this point doesn't know the meaning of JSON or API or "command line," and, furthermore, has every reason, once seeing "$ curl, blah..." to assume it's random stuff to be ignored, or that, at best, the labels in it are just labels, not things that can go in a URL. Edited to give specific tags to the student. -- BK
By viewing the source HTML for the page, you can devise a plan for extracting the right information from it.

Some Web sites also have ways for users to obtain more direct information. Read the details on ipinfo.io, and you'll find some really nice ways to directly extract the information you need. For example, ipinfo.io/72.229.28.185/loc returns just a latitude and longitude, instead of an HTML page. Check out ipinfo.io/72.229.28.185/city, /state, and /postal for ideas.
  1. Build the UMBRELLA? block block by using IP information as input to Weatherstreet. You'll need to figure out what information should make the block answer: UMBRELLA? block returning true.
    Remember, the true and false blocks are in the Operators panel.
  1. Change the UMBRELLA? block to a reporter that can return a wider variety of information, including outputs such as tonight, tomorrow, it's complicated, and wear boots instead.
  2. SUNSET TIME block with output
  3. Build a SUNSET TIME block reporter that returns the sunset time at a given location; if no location is provided, use the current location.