summaryrefslogtreecommitdiff
path: root/data/rbot/plugins
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-04 09:58:12 +0000
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2007-09-04 09:58:12 +0000
commite2f8ecd2aead7a4d3b226ab9a7884eed7e8552eb (patch)
tree3b6e2536f50281334430ede8e9a412f3ca65291f /data/rbot/plugins
parent06a3b39c7a3db68ac58b82a5fec1b30c61fc30af (diff)
lastfm plugin: support redirected location searches
Diffstat (limited to 'data/rbot/plugins')
-rw-r--r--data/rbot/plugins/lastfm.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/data/rbot/plugins/lastfm.rb b/data/rbot/plugins/lastfm.rb
index 6e7d4c71..9c6e97b9 100644
--- a/data/rbot/plugins/lastfm.rb
+++ b/data/rbot/plugins/lastfm.rb
@@ -14,6 +14,9 @@
require 'open-uri'
class ::LastFmEvent
+ # matches are:
+ # 1. day 2. moth 3. year 4. url_who 5. who 6. url_where 7. where 8. how_many
+ REGEXP = /<tr class="vevent\s+\w+\s+\S+?-(\d\d)-(\d\d)-(\d\d\d\d)\s*">.*?<a class="url summary" href="(\/event\/\d+)">(.*?)<\/a>.*?<a href="(\/venue\/\d+)">(.*?)<\/a>.*?<td class="attendance">(.*?)<\/td>\s+<\/tr>/m
attr_accessor :url, :date, :artist, :location, :attendance
def initialize(url, date, artist, location, attendance)
@url = url
@@ -81,12 +84,21 @@ class LastFmPlugin < Plugin
events = Array.new
disp_events = Array.new
- # matches are:
- # 1. day 2. moth 3. year 4. url_who 5. who 6. url_where 7. where 8. how_many
- pre_events = page.scan(/<tr class="vevent\s+\w+\s+\S+?-(\d\d)-(\d\d)-(\d\d\d\d)\s*">.*?<a class="url summary" href="(\/event\/\d+)">(.*?)<\/a>.*?<a href="(\/venue\/\d+)">(.*?)<\/a>.*?<td class="attendance">(.*?)<\/td>\s+<\/tr>/m)
+ pre_events = page.scan(LastFmEvent::REGEXP)
# debug pre_events.inspect
if pre_events.empty?
- m.reply "No events found #{spec}, sorry"
+ # We may not find any even because the page gives a list
+ # of locations instead. In this case, retry with the first of
+ # these location
+ if page.match(/<a href="(\/events\/\?l=[^"]+)">/)
+ debug "Rechecking with #{$1}"
+ page = @bot.httputil.get(LASTFM+$1)
+ pre_events = page.scan(LastFmEvent::REGEXP) if page
+ 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|
date = Time.utc(year.to_i, month.to_i, day.to_i)