A script to check whether PHE have updated their dashboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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