aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-09-25 13:22:53 +0200
committerHarald Eilertsen <haraldei@anduin.net>2018-09-25 13:22:53 +0200
commit082c6c1b049e5739f381cd76938ce5b330a68c27 (patch)
tree49a16ceadf71f619683bf6cfa7f1d440be9fc673
downloadramaskrik-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--Gemfile4
-rw-r--r--Gemfile.lock15
-rw-r--r--ramaskrik-program.rb23
3 files changed, 42 insertions, 0 deletions
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