Skip to content

Commit

Permalink
Decent extraction of today's forecast
Browse files Browse the repository at this point in the history
  • Loading branch information
jmason committed Jun 18, 2018
1 parent cde38eb commit 13a0ab6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Expand Up @@ -4,7 +4,5 @@

source "https://rubygems.org"

ruby "2.0.0"

gem "scraperwiki", git: "https://github.com/openaustralia/scraperwiki-ruby.git", branch: "morph_defaults"
gem "mechanize"
26 changes: 24 additions & 2 deletions scraper.rb
Expand Up @@ -10,10 +10,32 @@
page = agent.get("https://www.met.ie/forecasts/dublin")

# Find somehing on the page using css selectors
p page.at('div.forecast p')
text = page.at('div.forecast').text.strip

# "Issued at: 18 June 2018 17:00\n TODAY - Monday 18th June\n Largely cloudy this evening with some drizzle at times, and a few short bright spells.\n\n TONIGHT - Monday 18th June\n Dry with clear spells at first tonight, but it will turn cloudier with mist and drizzle through the second half of the night. Lows of 9 or 10 degrees in a light breeze.\n\n Grass Pollen Count\n High\n More information \n Solar UV Index\n Low to Moderate for Monday\n\n UV Index \n TOMORROW - Tuesday 19th June\n Tomorrow will be another cloudy day with spells of drizzle. It will gradually dry out through the day with some sunny breaks later in the afternoon. Highest temperatures of 18 to 22 degrees with a light easterly breeze.\n\n National Outlook\n"

text.gsub!(/[ \t]+/, ' ')
text.gsub!(/ *\n */, "\n")
#print text

text =~ /\nTODAY - (.+)\n(.*?)\n\n/is
todaydate = $1
todaycast = $2
print "TODAY [#{todaydate}] [#{todaycast}]\n"

text =~ /\nTOMORROW - (.+)\n(.*?)\n\n/is
tomozdate = $1
tomozcast = $2
print "TOMORROW [#{tomozdate}] [#{tomozcast}]\n"


# Write out to the sqlite database using scraperwiki library
ScraperWiki.save_sqlite(["day"], {"day" => "todo", "forecast" => page.at('div.forecast p')})
ScraperWiki.save_sqlite(["day"], {
"day" => todaydate,
"today_forecast" => todaycast,
"tomorrow" => tomozdate,
"tomorrow_forecast" => tomozdate
})

# An arbitrary query against the database
# ScraperWiki.select("* from data where 'name'='peter'")
Expand Down

0 comments on commit 13a0ab6

Please sign in to comment.