From 082c6c1b049e5739f381cd76938ce5b330a68c27 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Tue, 25 Sep 2018 13:22:53 +0200 Subject: Kick off a simple script to keep track of the ramaskrik programme. --- Gemfile | 4 ++++ Gemfile.lock | 15 +++++++++++++++ ramaskrik-program.rb | 23 +++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 ramaskrik-program.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..4592615 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +# frozen_string_literal: true +source "https://rubygems.org" + +gem "nokogiri" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..d6f0963 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,15 @@ +GEM + remote: https://rubygems.org/ + specs: + mini_portile2 (2.3.0) + nokogiri (1.8.4) + mini_portile2 (~> 2.3.0) + +PLATFORMS + ruby + +DEPENDENCIES + nokogiri + +BUNDLED WITH + 1.16.1 diff --git a/ramaskrik-program.rb b/ramaskrik-program.rb new file mode 100644 index 0000000..0ca62e2 --- /dev/null +++ b/ramaskrik-program.rb @@ -0,0 +1,23 @@ +require 'date' +require 'nokogiri' +require 'open-uri' + +class Movie + attr_reader :title, :start_time, :end_time, :venue + + def initialize(node) + @title = node.css("h4").text.strip + @start_time = DateTime.parse(node.css(".date").attribute('title').value) + @end_time = DateTime.parse(@start_time.strftime('%F') + node.css(".prgtype-endTime").text.strip.sub(/\w+/, '')) + @end_time += 1 if @end_time < @start_time + @venue = node.css(".place").text.strip + end + + def to_s + "#{title} #{start_time} - #{end_time}, #{venue}" + end +end + +doc = Nokogiri::HTML(open("program.html")) ## open("https://ramaskrik.no/program/")) +movies = doc.css(".kultur-type-movie").map { |movie| Movie.new(movie) } +puts movies -- cgit v1.2.3