Skip to content

Commit

Permalink
Adds Tiroler Landestheater
Browse files Browse the repository at this point in the history
  • Loading branch information
bonflintstone committed Oct 31, 2024
1 parent 889050f commit 8f94118
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def organization_color(organization)
"bg-purple-100"
when "Brux"
"bg-pink-100"
when "Tiroler Landestheater"
"bg-indigo-100"
end
end
end
2 changes: 1 addition & 1 deletion app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Event < ApplicationRecord
ORGANIZATIONS_BY_TYPE = {
'Kino': [ "Leokino" ],
'Theater': [ "Theater Praesent", "Haus der Musik", "Brux" ],
'Theater': [ "Theater Praesent", "Haus der Musik", "Brux", "Tiroler Landestheater" ],
'Musik und Kultur': [ "Treibhaus", "Die Bäckerei" ]
}
ORGANIZATIONS = ORGANIZATIONS_BY_TYPE.values.flatten.uniq
Expand Down
30 changes: 30 additions & 0 deletions app/services/fetch_tiroler_landestheater.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class FetchTirolerLandestheater
def self.call
response = HTTParty.get("https://www.landestheater.at/kalender/?spielzeit=aktuell")
document = Nokogiri::HTML(response.body)

# document.css('time').each { puts _1.attr('datetime') }

document.css("#listitems").children.each do |event_rows_by_date|
date = event_rows_by_date.css("a").attr("data-date")&.value&.then(&Date.method(:parse))

next if date.blank? || date < Date.today || date > 2.month.from_now

event_rows_by_date.css("> a").each do |event_row|
# puts event_row.text.gsub(/\s+/, ' ').strip

time = event_row.css(".info").text[/(\d\d\.\d\d)/]&.sub(".", ":")

next if time.blank?

datetime = Time.parse("#{date} #{time}", "%d.%m.%Y %H.%M")
name = event_row.css("h4").text
link = event_row.attr("href")
location = event_row.css(".info > span:first-child").text
description = event_row.css("h4 + span").text

Event.create(datetime:, name:, link:, location:, description:, organization: "Tiroler Landestheater")
end
end
end
end
1 change: 1 addition & 0 deletions app/services/refetch_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ def self.call
FetchBaeckerei.call
FetchHausDerMusik.call
FetchBrux.call
FetchTirolerLandestheater.call

RefetchEvent.create(new_event_count: Event.count)
end
Expand Down

0 comments on commit 8f94118

Please sign in to comment.