Created
July 6, 2014 20:53
-
-
Save meise/f3a9364173526adc33bf to your computer and use it in GitHub Desktop.
Ruby script that converts frab xml output file into info-beamer schedule.json file needed for https://github.com/dividuum/info-beamer-nodes/tree/master/30c3-room
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "rexml/document" | |
require 'pathname' | |
require 'json' | |
require 'date' | |
SCHEDULE_XML = Pathname('schedule.xml') | |
# C01 or B05/B06 or B07/B08 or A08 | |
ROOM_PATTERN = 'C01|B05\/B06|B07\/B08|B09|A08' | |
# Lunch or Coffe Break or Breakfast | |
SKIP_EVENTS = '[Ll]unch|[Cc]offee\s[Bb]reak|[Bb]reakfast' | |
def convert_duration_into_minutes(duration) | |
hour, minutes = duration.split(':') | |
hour.to_i*60+minutes.to_i | |
end | |
def read_schedule(xml_file) | |
REXML::Document.new File.read(xml_file) | |
end | |
def write_schedule_json(array) | |
File.open(Pathname('schedule.json'), 'w') { |file| file.write(array.to_json) } | |
end | |
events = read_schedule(SCHEDULE_XML).get_elements('//event') | |
all_events = [] | |
events.each do |event| | |
next unless event.elements['room'].text =~ /#{ROOM_PATTERN}/ | |
next if event.elements['title'].text =~ /#{SKIP_EVENTS}/ | |
hash = {} | |
hash['duration'] = convert_duration_into_minutes(event.elements['duration'].text) | |
event.elements['language'] ? hash['lang'] = event.elements['language'].text : hash['lang'] = '' | |
hash['place'] = event.elements['room'].text | |
hash['speakers'] = event.get_elements('./persons').map{ |p| p.elements['person'].text } | |
hash['start'] = event.elements['start'].text | |
hash['title'] = event.elements['title'].text | |
hash['type'] = event.elements['type'].text | |
hash['unix'] = DateTime.parse(event.elements['date'].text).to_time.to_i | |
hash['unix_end'] = (DateTime.parse(event.elements['date'].text).to_time + hash['duration']).to_i | |
all_events << hash | |
end | |
write_schedule_json(all_events) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment