Sha256: 04db0a08374879d602afc71e7608d9dcd95b213c8ffe88287d3d4a9f5836854a
Contents?: true
Size: 1.45 KB
Versions: 19
Compression:
Stored size: 1.45 KB
Contents
=begin rdoc nasa_apod.rb -- oneline desc Time-stamp: <2013-10-15 00:17:15 tamara> Copyright (C) 2013 Tamara Temple Web Development Author: Tamara Temple <tamouse@gmail.com> License: MIT == Discussion NASA's Astronomy Picture of the Day is a great source for nice astro photos and various other information. But it isn't something I remember to go see every day, so I'd like it to drop in my in-box or an evernote notebook. But the feed does not include the image, for some ungodly reason, so I'm adding a scraper to grab the nice info off the page including the photo. =end module Scrapers module NasaApod NASA_APOD_URL="http://asterisk.apod.com/library/APOD/APOD%20mirror/astropix.html" module_function def scrape(url=nil) url ||= NASA_APOD_URL apod = Hash.new Mechanize.start do |m| m.get url # APOD has a funky entry page, but we want the actual page prev = m.current_page.link_with(:text => '<').href m.get prev canonical = m.current_page.link_with(:text => '>' ).href m.get canonical m.current_page.tap do |page| apod[:title] = page.title.strip apod[:link] = page.uri.to_s apod[:description] = (page/("body")).text apod[:pubDate] = page.response['date'].to_s apod[:guid] = page.uri.to_s apod[:content_encoded] = (page/("body")).to_html end end apod end end end
Version data entries
19 entries across 19 versions & 1 rubygems