From 1fc3684a18d819d5861319dc0c04aedaad4a9de5 Mon Sep 17 00:00:00 2001 From: mburtonkelly Date: Wed, 31 Oct 2018 16:36:54 -0500 Subject: [PATCH] Update API version and grab all the requests from the last week. --- bin/gfk-publicstuff.R | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/bin/gfk-publicstuff.R b/bin/gfk-publicstuff.R index 9c69925..6be2abf 100644 --- a/bin/gfk-publicstuff.R +++ b/bin/gfk-publicstuff.R @@ -1,7 +1,23 @@ +## +# R script to get data from PublicStuff +# Note that the API version at https://www.publicstuff.com/developers#!/API is v2.0, +# but this only includes requests up to a certain date. Use v2.1 for recent requests. + library(rjson) # Grab city view for Grand Forks -gfk <- fromJSON(file="https://www.publicstuff.com/api/2.0/city_view?space_id=15174") - +gfk <- fromJSON(file="https://www.publicstuff.com/api/2.1/city_view?space_id=15174") ## Make a data frame of request_type IDs and names -gfk_request_types <- as.data.frame(t(sapply(gfk$response$request_types$request_types, function(x) c(x$request_type$id, x$request_type$name)))) +gfk_request_types <- as.data.frame(t(sapply(gfk$response$request_types$request_types, + function(x) c(x$request_type$id, x$request_type$name)))) +# Add column names +names(gfk_request_types) <- c("request_type_id","request_type_name") +# Loop through request types and get n most recent in each category +# Unix timestamp from a week ago +today <- as.numeric(as.POSIXct(Sys.time())) +week_ago <- today-604800 +gfk_requests <- lapply(gfk_request_types$request_type_id, + function(x) fromJSON(file=paste0("https://www.publicstuff.com/api/2.1/requests_list?request_type_id=", + x,"&after_timestamp=",week_ago,"&limit=10"))) + +