aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Gemfile5
-rw-r--r--Gemfile.lock4
-rw-r--r--ramaskrik-program.rb25
3 files changed, 33 insertions, 1 deletions
diff --git a/Gemfile b/Gemfile
index 4592615..ac8d438 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,3 +2,8 @@
source "https://rubygems.org"
gem "nokogiri"
+gem "svg-graph"
+
+group :development do
+ gem "byebug"
+end
diff --git a/Gemfile.lock b/Gemfile.lock
index d6f0963..5aff6f4 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,15 +1,19 @@
GEM
remote: https://rubygems.org/
specs:
+ byebug (10.0.2)
mini_portile2 (2.3.0)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
+ svg-graph (2.1.3)
PLATFORMS
ruby
DEPENDENCIES
+ byebug
nokogiri
+ svg-graph
BUNDLED WITH
1.16.1
diff --git a/ramaskrik-program.rb b/ramaskrik-program.rb
index 0ca62e2..9097522 100644
--- a/ramaskrik-program.rb
+++ b/ramaskrik-program.rb
@@ -1,6 +1,7 @@
require 'date'
require 'nokogiri'
require 'open-uri'
+require 'SVG/Graph/Schedule'
class Movie
attr_reader :title, :start_time, :end_time, :venue
@@ -16,8 +17,30 @@ class Movie
def to_s
"#{title} #{start_time} - #{end_time}, #{venue}"
end
+
+ def triplet
+ [@title, @start_time.strftime("%d.%m.%Y %H:%M"), @end_time.strftime("%d.%m.%Y %H:%M")]
+ 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
+days = movies.group_by { |movie| movie.start_time.strftime("%A %d.%m.%Y") }
+days.each do |d, movies|
+ graph = SVG::Graph::Schedule.new({
+ graph_title: d,
+ show_graph_title: true,
+ show_x_guidelines: true,
+ width: 1024,
+ key: false,
+ x_label_format: "%H:%M"
+ })
+
+ venues = movies.group_by { |m| m.venue }
+ venues.each do |v, m|
+ data = m.flat_map { |m| m.triplet }
+ graph.add_data({ title: v, data: data })
+ end
+
+ IO.write("#{d}-program.svg", graph.burn())
+end