From 0611a5e9fdc6cdd7adf9a0acd68db47606884173 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Mon, 31 Dec 2007 00:44:20 +0000 Subject: [PATCH] lastfm plugin: update event parsing --- data/rbot/plugins/lastfm.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/data/rbot/plugins/lastfm.rb b/data/rbot/plugins/lastfm.rb index 09ea3803..28279881 100644 --- a/data/rbot/plugins/lastfm.rb +++ b/data/rbot/plugins/lastfm.rb @@ -12,9 +12,13 @@ # License:: GPL v2 class ::LastFmEvent + SELECTOR = /.*?(.*?)<\/a>.*?(.*?)<\/a>.*?(.*?)<\/td>\s+<\/tr>/m + # TODO festival have TWO dates -------+ + # TODO event type -------------+ | + # V V + MATCHER = /.*?(.*?)<\/a>.*?(.*?)<\/a>.*?(?:(.*?) attending\s+)?.*?<\/td>\s+<\/tr>/m attr_accessor :url, :date, :artist, :location, :attendance def initialize(url, date, artist, location, attendance) @url = url @@ -76,7 +80,7 @@ class LastFmPlugin < Plugin events = Array.new disp_events = Array.new - pre_events = page.scan(LastFmEvent::REGEXP) + pre_events = page.scan(LastFmEvent::SELECTOR) # debug pre_events.inspect if pre_events.empty? # We may not find any even because the page gives a list @@ -85,14 +89,16 @@ class LastFmPlugin < Plugin if page.match(//) debug "Rechecking with #{$1}" page = @bot.httputil.get(LASTFM+$1) - pre_events = page.scan(LastFmEvent::REGEXP) if page + debug page + pre_events = page.scan(LastFmEvent::SELECTOR) if page + debug pre_events end if pre_events.empty? m.reply "No events found #{spec}, sorry" return end end - pre_events.each { |day, month, year, url_who, who, url_where, where, how_many| + pre_events.each { |s| s.scan(LastFmEvent::MATCHER) { |day, month, year, url_who, who, url_where, where, how_many| date = Time.utc(year.to_i, month.to_i, day.to_i) url = LASTFM + url_who if who.match(/(.*?)<\/strong>(.+)?/) @@ -109,9 +115,9 @@ class LastFmPlugin < Plugin debug where.inspect loc = where.ircify_html end - attendance = how_many.ircify_html + attendance = how_many ? how_many.ircify_html : '' events << LastFmEvent.new(url, date, artist, loc, attendance) - } + } } # debug events.inspect events[0...num].each { |event| -- 2.39.5