diff --git a/app/models/event.rb b/app/models/event.rb index d6e2229..a13d3e6 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -1,5 +1,5 @@ class Event < ApplicationRecord - ORGANIZATIONS = ["Leokino", "Theater Praesent", "Treibhaus", "Die Bäckerei", "Haus der Musik"] + ORGANIZATIONS = [ "Leokino", "Theater Praesent", "Treibhaus", "Die Bäckerei", "Haus der Musik" ] validates :name, :location, :datetime, :link, presence: true validates :organization, inclusion: { in: ORGANIZATIONS } diff --git a/app/services/fetch_haus_der_musik.rb b/app/services/fetch_haus_der_musik.rb index 274bb9b..25e75c4 100644 --- a/app/services/fetch_haus_der_musik.rb +++ b/app/services/fetch_haus_der_musik.rb @@ -3,16 +3,16 @@ def self.call response = HTTParty.get("https://www.haus-der-musik-innsbruck.at/kalender/") document = Nokogiri::HTML(response.body) - document.css('.EventList article').map do |event_row| - datetime = event_row.css('time').attr('datetime')&.then(&Time.method(:parse)) - next unless datetime.present? + document.css(".EventList article").map do |event_row| + datetime = event_row.css("time").attr("datetime")&.then(&Time.method(:parse)) + next unless datetime.present? - name = event_row.css('h2.title-5').text.strip - description = event_row.css('.info span:first-child').text - location = event_row.css('.stats .stat:nth-child(2) strong').text - link = 'https://www.haus-der-musik-innsbruck.at' + event_row.css('.info a').attr('href').value + name = event_row.css("h2.title-5").text.strip + description = event_row.css(".info span:first-child").text + location = event_row.css(".stats .stat:nth-child(2) strong").text + link = "https://www.haus-der-musik-innsbruck.at" + event_row.css(".info a").attr("href").value - Event.create(datetime:, location:, name:, link:, description:, organization: 'Haus der Musik').errors + Event.create(datetime:, location:, name:, link:, description:, organization: "Haus der Musik").errors end end end diff --git a/app/services/fetch_leokino.rb b/app/services/fetch_leokino.rb index bd2183e..2577737 100644 --- a/app/services/fetch_leokino.rb +++ b/app/services/fetch_leokino.rb @@ -13,7 +13,7 @@ def self.call location = movie_row.css("td:first-child h3:last-of-type").text.strip name = movie_row.css("td:last-child h3 a").children.map(&:text).join(" - ") link = "https://leokino.at" + movie_row.css("td:last-child h3 a").attr("href").value - description = movie_row.css("td:last-child p:last-child").text.sub('[ mehr ]', '').strip + description = movie_row.css("td:last-child p:last-child").text.sub("[ mehr ]", "").strip Event.create(datetime:, location:, name:, link:, description:, organization: "Leokino") end