# 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|
graph = SVG::Graph::RoomSchedule.new({
graph_title: d,
show_graph_title: true,
show_x_guidelines: true,
width: 1280,
key: false,
x_label_format: "%H:%M",
timescale_divisions: "30 minutes",
})
movies.group_by { |m| m.venue }.each do |title, data|
graph.add_data(title: title, data: data)
end
IO.write("#{d}-program.svg", graph.burn())
end