Created
July 22, 2013 17:42
-
-
Save 46bit/6055910 to your computer and use it in GitHub Desktop.
A BBC Prom information service for Yoleaux (https://github.com/dpk/yoleaux), available at http://photos.46bit.com. Add to yoleaux with:
.add-command prom http://photos.46bit.com/{$args}
Egs: .prom (today's proms), .prom 1 (tomorrow's proms), .prom 7 (proms this day next week)
This file contains hidden or 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
| require 'nokogiri' | |
| require 'httparty' | |
| require 'active_support/time' | |
| require 'sinatra' | |
| def prom_string days_time | |
| headers = {"User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36"} | |
| response = HTTParty.get "http://www.bbc.co.uk/proms/whats-on/2013/print-season", :headers => headers | |
| body = response.body | |
| doc = Nokogiri::HTML(body) | |
| date = days_time.day.from_now.to_date | |
| # Eg: Friday 12 July | |
| date_str = date.strftime "%A %-d %B" | |
| =begin | |
| Find %h2.day with that content | |
| Find sibling .eventlist | |
| For each li, | |
| h3.content (h4.content) | |
| =end | |
| h2s = doc.css("h2.day") | |
| this_h2 = false | |
| h2s.each do |h2| | |
| # puts h2.content.strip | |
| if h2.content.strip == date_str | |
| # puts date_str | |
| this_h2 = h2 | |
| break | |
| end | |
| end | |
| exit unless this_h2 | |
| eventlist = this_h2.next_element()# .css(".eventlist") | |
| if eventlist#.length > 0 | |
| # proms = eventlist[0].css("li").map do |li| | |
| proms = eventlist.css("li").map do |li| | |
| h3c = li.css("h3")[0].content | |
| h4s = li.css("h4") | |
| str = h3c | |
| if h4s.length > 0 | |
| str << " from " << h4s[0].content << "" | |
| end | |
| str | |
| end | |
| date_str + "\n" + proms.join(" \n") | |
| else | |
| "No proms!" | |
| end | |
| end | |
| get '/' do | |
| days_time = 0 | |
| prom_string(days_time) | |
| end | |
| get '/:days_time' do |days_time| | |
| prom_string(days_time.to_i) | |
| end | |
| #days_time = ARGV[0].to_i # 1 | |
| #puts prom_string(days_time) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment