Skip to content

Instantly share code, notes, and snippets.

@smach
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smach/1660f6cf3d8a68440024 to your computer and use it in GitHub Desktop.
Save smach/1660f6cf3d8a68440024 to your computer and use it in GitHub Desktop.
atlantawx.R
url <- "http://forecast.weather.gov/MapClick.php?lat=33.74899931200048&lon=-84.38797796399967&site=all&smap=1#.VPUbWfnF9EI"
library(rvest)
html <- html(url)
forecasthtml <- html_nodes(html, ".row-forecast")
forecast <- html_text(forecasthtml)
# Note: to deal with the lack of spaces now between Today, Tonight, etc. and the start of the forecasts, I added
forecast_formatted <- gsub("day([A-Z])", "day \\1", forecast)
forecast_formatted <- gsub("Night([A-Z])", "Night \\1", forecast_formatted)
forecast_formatted <- gsub("Tonight([A-Z])", "Tonight \\1", forecast_formatted)
forecast_formatted <- gsub("Afternoon([A-Z])", "Afternoon \\1", forecast_formatted)
forecast_formatted <- gsub("Day([A-Z])", "Day \\1", forecast_formatted)
# This last line just prints it out nicely on the screen. Could also save to variable or file.
cat(paste(forecast_formatted, collapse = "\n\n"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment