aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--index.html.erb12
-rw-r--r--ramaskrik-program.rb52
2 files changed, 43 insertions, 21 deletions
diff --git a/index.html.erb b/index.html.erb
new file mode 100644
index 0000000..f1dfbf0
--- /dev/null
+++ b/index.html.erb
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Ramaskrik 2018 programoversikt</title>
+ </head>
+ <body>
+ <h1>Ramaskrik 2018 programoversikt</h1>
+ <% generate_graphs do |graph| %>
+ <%= graph.burn_svg_only() %>
+ <% end %>
+ </body>
+</html>
diff --git a/ramaskrik-program.rb b/ramaskrik-program.rb
index c2ba006..3c56edc 100644
--- a/ramaskrik-program.rb
+++ b/ramaskrik-program.rb
@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
require 'date'
+require 'erb'
require 'nokogiri'
require 'open-uri'
require 'room-schedule'
@@ -37,26 +38,35 @@ class Movie
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
+def scrape_program
+ doc = Nokogiri::HTML(open("https://ramaskrik.no/program/"))
+ doc.css(".kultur-type-movie").map { |movie| Movie.new(movie) }
+end
+
+def generate_graphs
+ days = scrape_program.group_by { |movie| movie.start_time.strftime("%A %d.%m.%Y") }
+ days.map 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",
+ })
- IO.write("#{d}-program.svg", graph.burn())
+ rooms.each do |title, data|
+ graph.add_data(title: title, data: data)
+ end
+
+ yield graph
+ end
end
+
+t = ERB.new(IO.read("index.html.erb"))
+IO.write("index.html", t.result(binding))
+