aboutsummaryrefslogtreecommitdiffstats
path: root/ramaskrik-program.rb
blob: a9af3a0f01ce726ce2090b957e45ac795a5a9053 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Ramaskrik Program Schedule plotter.
# Copyright (C) 2018  Harald Eilertsen <haraldei@anduin.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

require 'date'
require 'nokogiri'
require 'open-uri'
require 'room-schedule'

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) }
days = movies.group_by { |movie| movie.start_time.strftime("%A %d.%m.%Y") }
days.each do |d, movies|
  rooms = movies.group_by { |m| m.venue }.delete_if { |t, _| t == "Ramaskrik" }

  graph = SVG::Graph::RoomSchedule.new({
    graph_title: d,
    show_graph_title: true,
    show_x_guidelines: true,
    width: 1280,
    height: rooms.keys.length * 100 + 25,
    key: false,
    x_label_format: "%H:%M",
    timescale_divisions: "30 minutes",
  })

  rooms.each do |title, data|
    graph.add_data(title: title, data: data)
  end

  IO.write("#{d}-program.svg", graph.burn())
end