From 8f941186b5d88d1be47c69269195cab8ead5d2b1 Mon Sep 17 00:00:00 2001 From: Bonflintstone Date: Thu, 31 Oct 2024 10:12:06 +0100 Subject: [PATCH] Adds Tiroler Landestheater --- app/helpers/application_helper.rb | 2 ++ app/models/event.rb | 2 +- app/services/fetch_tiroler_landestheater.rb | 30 +++++++++++++++++++++ app/services/refetch_all.rb | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 app/services/fetch_tiroler_landestheater.rb diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index aeefdb9..9e6c2f3 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index 1f84519..2980fff 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 diff --git a/app/services/fetch_tiroler_landestheater.rb b/app/services/fetch_tiroler_landestheater.rb new file mode 100644 index 0000000..60b0b53 --- /dev/null +++ b/app/services/fetch_tiroler_landestheater.rb @@ -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 diff --git a/app/services/refetch_all.rb b/app/services/refetch_all.rb index 4354b2b..c9e4263 100644 --- a/app/services/refetch_all.rb +++ b/app/services/refetch_all.rb @@ -8,6 +8,7 @@ def self.call FetchBaeckerei.call FetchHausDerMusik.call FetchBrux.call + FetchTirolerLandestheater.call RefetchEvent.create(new_event_count: Event.count) end