2015-August Scripting Games Puzzle

Scripting Games

Our August 2015 puzzler tests your ability to retrieve data from the Web. If you’ve never done this before, it can be a real brain-bender – but don’t overthink it; experts can probably pull this off in a one-liner if they’re using a newer version of PowerShell!

Instructions

The Scripting Games have been re-imagined as a monthly puzzle. We publish puzzles the first Saturday of each month, along with solutions and commentary for the previous month’s puzzle. You can find them all at https://powershell.org/category/announcements/scripting-games/. Many puzzles will include optional challenges, that you can use to really push your skills.

To participate, add your solution to a public Gist (http://gist.github.com; you’ll need a free GitHub account, which all PowerShellers should have anyway). After creating your public Gist, just copy the URL from your browser window and paste it, by itself, as a comment of this post. Only post one entry per person. You are not allowed to come back and post corrected or improved versions. If you do, all of your posts will be ignored. However, remember that you can always go back and edit your Gist. We’ll always pull the most recent one when we display it, so there’s no need to post multiple entries if you want to make an edit.

Don’t forget the main rules and purpose of these monthly puzzles, including the fact that you won’t receive individual scoring or commentary on your entry.

User groups are encouraged to work together on the monthly puzzles. User group leaders should submit their group’s best entry to Ed Wilson, the Scripting Guy, via e-mail, prior to the third Saturday of the month. On the last Saturday of the month, Ed will post his favorite, along with commentary and excerpts from noteworthy entries. The user group with the most “favorite” entries of the year will win a grand prize from PowerShell.org.

 

Our Puzzle

At www.telize.com/geoip, you’ll find a JavaScript Object Notation endpoint. It’s public. Your goal is to get PowerShell to display something like the following (because this is based on your IP address, the property values will be different than what’s shown here):

longitude latitude continent_code timezone
--------- -------- -------------- --------
-115.1685 36.2212  NA             America/Los_Angeles

Being able to query information from the Web – often in XML or JavaScript Object Notation – is an important integration skill. PowerShell can actually make it pretty easy. Although this challenge can be solved using a one-liner, you could also go further and write a complete “Get-GeoInformation” function around it. However, keep in mind that a function would not normally (a) limit the data that’s output or (b) pre-format the data. Why not?

Challenges:

  • Try to do this in a one-liner, but spell out all command and parameter names.
  • Write an advanced function that provides a complete Get-GeoInformation “wrapper” around this endpoint.
  • Along with your entry, include the endpoint for another XML or JavaScript Object Notation web service that you think is cool, along with a brief notation of what it does

 

27 Responses to " 2015-August Scripting Games Puzzle "

  1. My one-liner and advanced function:
    https://gist.github.com/andrewrmoreland/7deae2fe2995ea445645
    Another REST API along the same theme that I find cool is http://www.uk-postcodes.com/api, which returns useful information about a UK postcode.

  2. kvprasoon says:

    Onliner Using JSON
    Invoke-WebRequest -Uri http://www.telize.com/geoip|select -ExpandProperty content|ConvertFrom-Json|select longitude,latitude,country_code,timezone
    Detailed info in Gist
    https://gist.github.com/kvprasoon/c1bdd4192c3031fd29f5

  3. selene v says:
    invoke-webrequest -uri "http://www.telize.com/geoip"  | ConvertFrom-Json | ft -autosize longitude,latitude,continent_code,timezone
  4. […] If you haven’t heard, PowerShell.org is taking the lead on organizing the PowerShell Scripting Games. There’s a new format that involves monthly puzzles. Here’s their post on August’s puzzle: https://powershell.org/2015/08/01/august-2015-scripting-games-puzzle/ […]

  5. Here is a post explaining what I did: http://www.workingsysadmin.com/my-august-2015-scripting-puzzle-solution/
    Here is the Gist showing my code:

  6. Here’s my response:
    This is written for PowerShell v2; I did that because it seemed like a harder challenge to me.
    This will really only work for fairly simple, flat JSON (no array values or inner hash tables, no extra white space), so I won’t call it a great job, but it can be improved upon to make it handle more that it currently does.

  7. […] have not yet had a chance to check out the August edition of the 2015 Scripting Games head over to PowerShell.org and get involved! I have been absolutely swamped this last week so I am just getting a chance to […]

  8. Challenge Entry: https://gist.github.com/MSAdministrator/d07789031f11529412d9
    Seperate object notation web service. I’ve been developing functions for the QualysGuard API. QualysGuard Vulnerability Mangement API contains detailed data about vulnerabilities on hosts within our environment. Check it out here: https://github.com/MSAdministrator/QualysGuard-V1-API—PowerShell

  9. […] the PowerShell.org Scripting Games Puzzle for August is about to expire, so rather later than never I decided to give it a go and meet the challenges […]

  10. Dean Grant says:

    Here is my attempt, including functionality for specifying single or multiple IP addresses with validation and protocol selection. By default will retrieve IP geolocation data for the public address of the local host and use HTTPS.
    https://github.com/dean1609/PowerShell/blob/master/ScriptingGames/Get-GeoIP.ps1

  11. […] August puzzler was intended to highlight the usefulness of REST APIs, and the relative ease with which you can […]

  12. […] announced that the PowerShell Scripting Games had been re-imagined as a monthly puzzle. In August, the second puzzle was […]