Skip to content

Instantly share code, notes, and snippets.

@dstreefkerk
Created April 23, 2015 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstreefkerk/cf23a7d8a818f28cb36f to your computer and use it in GitHub Desktop.
Save dstreefkerk/cf23a7d8a818f28cb36f to your computer and use it in GitHub Desktop.
Retrieves data from https://data.cityofchicago.org and shows the last 1 month's crime data
# Get the data, convert it to JSON
$jsonData = Invoke-WebRequest "https://data.cityofchicago.org/resource/ijzp-q8t2.json" | ConvertFrom-Json
# Filter our data set down to only the last month's crimes. Note that the data feed has a built-in lag of 7 days
$lastMonthsData = $jsonData | Where-Object {($_.date | get-date) -gt ((get-date).AddMonths(-1))}
# Show results, allowing user to select categories first and then view individual crimes
$lastMonthsData | Group-Object -Property primary_type | Sort-Object Count -Descending | Select-Object Name,Count,Group | Out-GridView -Title "Select a category (or multiple) to view details" -OutputMode Multiple | Select-Object -ExpandProperty Group | select primary_type,description,location_description,date,latitude,longitude,block,domestic,arrest,case_number | Sort-Object date -Descending | Out-GridView -Title "Crime Details"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment