Only try posting if there are requests to post.
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
# Run with `Rscript bin/gfk-publicstuff.R`
|
||||
|
||||
# Raspberry Pi: https://www.r-bloggers.com/how-to-install-the-latest-version-of-r-statistics-on-your-raspberry-pi/
|
||||
# Can install with sudo apt-get install... but it is 3.1.1 by default.
|
||||
|
||||
library(jsonlite)
|
||||
library(rjson)
|
||||
@ -79,11 +80,15 @@ mastodon_token <- login(auth$mastodon$server, auth$mastodon$email, auth$mastodon
|
||||
|
||||
# Each time this script runs, take the oldest n requests, post them, and mark them in the db.
|
||||
mydb <- dbConnect(RSQLite::SQLite(), "requests.sqlite")
|
||||
new_requests <- dbGetQuery(mydb, 'SELECT * FROM requests WHERE posted IS NULL ORDER BY date_created')
|
||||
#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){
|
||||
# One post per request, up to limit
|
||||
for(i in 1:posts_at_once){
|
||||
request <- new_requests[i,]
|
||||
# Post one selected request
|
||||
@ -106,6 +111,7 @@ for(i in 1:posts_at_once){
|
||||
}
|
||||
# Get out of the database
|
||||
dbDisconnect(mydb)
|
||||
}
|
||||
|
||||
#### Tweeting
|
||||
# You now need a developer account to set up an app, which takes some time.
|
||||
|
BIN
requests.sqlite
BIN
requests.sqlite
Binary file not shown.
Reference in New Issue
Block a user