diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2018-09-25 20:51:40 +0200 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2018-09-25 20:51:40 +0200 |
commit | fdbc3ad8a7ce49ab9745a61e79a34b59d754bbc0 (patch) | |
tree | 938e46e67b7ce722c78b5603d0d8eaddc83f2f9d | |
parent | 082c6c1b049e5739f381cd76938ce5b330a68c27 (diff) | |
download | ramaskrik-program-fdbc3ad8a7ce49ab9745a61e79a34b59d754bbc0.tar.gz ramaskrik-program-fdbc3ad8a7ce49ab9745a61e79a34b59d754bbc0.tar.bz2 ramaskrik-program-fdbc3ad8a7ce49ab9745a61e79a34b59d754bbc0.zip |
Add svg-graph gem to plot schedule.
Not quite what I expected, but at least we're on to something.
-rw-r--r-- | Gemfile | 5 | ||||
-rw-r--r-- | Gemfile.lock | 4 | ||||
-rw-r--r-- | ramaskrik-program.rb | 25 |
3 files changed, 33 insertions, 1 deletions
@@ -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 |