diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-09-25 13:22:53 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-09-25 13:22:53 +0200 |
commit | 082c6c1b049e5739f381cd76938ce5b330a68c27 (patch) | |
tree | 49a16ceadf71f619683bf6cfa7f1d440be9fc673 | |
download | ramaskrik-program-082c6c1b049e5739f381cd76938ce5b330a68c27.tar.gz ramaskrik-program-082c6c1b049e5739f381cd76938ce5b330a68c27.tar.bz2 ramaskrik-program-082c6c1b049e5739f381cd76938ce5b330a68c27.zip |
Kick off a simple script to keep track of the ramaskrik programme.
-rw-r--r-- | Gemfile | 4 | ||||
-rw-r--r-- | Gemfile.lock | 15 | ||||
-rw-r--r-- | ramaskrik-program.rb | 23 |
3 files changed, 42 insertions, 0 deletions
@@ -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 |