# Ramaskrik Program Schedule plotter. # Copyright (C) 2018 Harald Eilertsen # # 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 . require 'date' require 'nokogiri' require 'open-uri' require 'room-schedule' require 'uri' class Movie attr_reader :title, :link, :start_time, :end_time, :venue def initialize(node) @title = node.css("h4").text.strip @link = URI.join("https://ramaskrik.no", node.css("h4 a").attribute('href').value) @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("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