Skip to content

Commit

Permalink
Adds brux
Browse files Browse the repository at this point in the history
  • Loading branch information
bonflintstone committed Oct 29, 2024
1 parent 290d163 commit e6c3893
Show file tree
Hide file tree
Showing 3 changed files with 22 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 @@ -11,6 +11,8 @@ def organization_color(organization)
"bg-green-100"
when "Haus der Musik"
"bg-purple-100"
when "Brux"
"bg-pink-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,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", "Brux" ]

validates :name, :location, :datetime, :link, presence: true
validates :organization, inclusion: { in: ORGANIZATIONS }
Expand Down
19 changes: 19 additions & 0 deletions app/services/fetch_brux.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class FetchBrux
def self.call
response = HTTParty.get("https://brux.at/spielplan")
document = Nokogiri::HTML(response.body)

document.css("article[data-spielstaette]").each do |event_row|
datetime = event_row.css('[itemprop="startDate"]').attr("content")&.then(&Time.method(:parse))

next unless datetime.present?

name = event_row.css("a.c-link").text.strip
link = "https://www.brux.at/" + event_row.css("a.c-link").attr("href").value
description = event_row.css("p").text.strip
location = "Brux"

pp Event.create(datetime:, location:, name:, link:, description:, organization: "Brux").errors
end
end
end

0 comments on commit e6c3893

Please sign in to comment.