From c8b9c60b743a5d4d1cb4fc87619414e33ff26aae Mon Sep 17 00:00:00 2001 From: mburtonkelly Date: Fri, 2 Nov 2018 14:47:57 -0500 Subject: [PATCH] Clean up tooting and rename files. --- bin/{gfk-publicstuff.R => post-311.R} | 17 ++++++++++++----- post-311.bat | 1 + requests.sqlite | Bin 16384 -> 16384 bytes 3 files changed, 13 insertions(+), 5 deletions(-) rename bin/{gfk-publicstuff.R => post-311.R} (91%) create mode 100644 post-311.bat diff --git a/bin/gfk-publicstuff.R b/bin/post-311.R similarity index 91% rename from bin/gfk-publicstuff.R rename to bin/post-311.R index 91963ec..3901365 100644 --- a/bin/gfk-publicstuff.R +++ b/bin/post-311.R @@ -56,8 +56,8 @@ recent_requests <- lapply(recent_requests, drop_image) recent_requests <- bind_rows(recent_requests) # Add URL recent_requests$url <- paste0("https://iframe.publicstuff.com/#?client_id=",client_id,"&request_id=",recent_requests$id) -# Add posted column (to include in database table) -recent_requests$posted <- NA +# Add posted column (to include in database table) and default to 0 (false) +recent_requests$posted <- 0 ## Store requests in a database # Create DB if it doesn't exist, otherwise connect @@ -83,11 +83,12 @@ mydb <- dbConnect(RSQLite::SQLite(), "requests.sqlite") #all_requests <- dbGetQuery(mydb, 'SELECT * FROM requests') new_requests <- dbGetQuery(mydb, 'SELECT * FROM requests WHERE posted <> 1 ORDER BY date_created') -# Set number of posts allowed at once. Will need to adjust according to cron -# schedule and number of posts coming in daily so you don't get behind. -posts_at_once <- 3 + # Only post if there are new requests if(nrow(new_requests) > 0){ + # Set number of posts allowed at once. Will need to adjust according to cron + # schedule and number of posts coming in daily so you don't get behind. + posts_at_once <- min(3, nrow(new_requests)) # One post per request, up to limit for(i in 1:posts_at_once){ request <- new_requests[i,] @@ -111,6 +112,12 @@ if(nrow(new_requests) > 0){ } # Get out of the database dbDisconnect(mydb) + + # Message to console (if running from script) + print("Successful toots.") +} else { + # Message to console (if running from script) + print("No requests to toot.") } #### Tweeting diff --git a/post-311.bat b/post-311.bat new file mode 100644 index 0000000..103d43f --- /dev/null +++ b/post-311.bat @@ -0,0 +1 @@ +"C:\Program Files\R\R-3.4.4\bin\x64\Rscript.exe" bin\post-311.R \ No newline at end of file diff --git a/requests.sqlite b/requests.sqlite index 4a5bcdbd823d162bab9a1ba9b06cfad1fddc2812..80506c98a0272f21f8ec3c3234c6607035897654 100644 GIT binary patch delta 350 zcmZo@U~Fh$oFL68HBrWyQEFqt5`8Xao+<`DdEOYFs*Qy?JoSz7d=kvO+Ks~Un!F4w z92^|%>_CEFv{8`LZ^q2vlA_eqlAO%+j1mR^(h?sqBfqpnAwN&SC@)1Ju`D&OG*uy~ zQX$gU*-@b&C$TcUD8CdW1H_qmP~pU)?99A$g`E5nz2efO+{}`a)D$BFLsJC>MLz}e zk_?65lIS}NydB)XsUP~z5OyHKDP{5O{3C{rx%tJD?S*XXO${u}jT;?!#eq(ZmDfgg zDKE&S(~{9#ip&MM7wD9GBS%55>rx&Qj3e>&M`IuIVU_ZCl9C^C<{&i