Skip to content

Instantly share code, notes, and snippets.

@ryanleewatts
Last active Apr 28, 2020
Embed
What would you like to do?
A script to check whether PHE have updated their dashboard
# Check if we have new data
library(pacman)
p_load("slackr", "naptime", "lubridate")
# Set up a repeating loop
repeat{
# Check the current time
start_time <- lubridate::now()
# Download and read the file
download.file("https://coronavirus.data.gov.uk/downloads/csv/coronavirus-cases_latest.csv", "export/phe_data.csv", method = "libcurl")
data <- read.csv("export/phe_data.csv")
# Check if the latest date in the data is yesterday (which means the data has been updated)
if(max(as.Date(data$Specimen.date)) == Sys.Date()-1) {
# Send a message to a Slack channel and tag two teams
slackr_bot("*NEW DATA*: Public Health England have updated the coronavirus dashboard :chart_with_upwards_trend: <@data-and-interactives> <@graphics>",
username="Coronavirus Data Bot", channel="#channel",
incoming_webhook_url="https://hooks.slack.com/services/XXX")
break
}
# No new data? Wait two minutes and try again
print(paste("No new data as of",Sys.time(),sep=" "))
naptime(start_time + lubridate::minutes(2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment