diff options
Diffstat (limited to 'lib/update_importer.rb')
| -rw-r--r-- | lib/update_importer.rb | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/lib/update_importer.rb b/lib/update_importer.rb index ed53ef3..77d27b2 100644 --- a/lib/update_importer.rb +++ b/lib/update_importer.rb | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | require 'vpim/icalendar' | ||
| 1 | require 'rexml/document' | 2 | require 'rexml/document' |
| 2 | require 'iconv' | 3 | require 'iconv' |
| 3 | 4 | ||
| @@ -116,10 +117,65 @@ class UpdateImporter | |||
| 116 | if (flags = xhtml.elements['flags']) && page | 117 | if (flags = xhtml.elements['flags']) && page |
| 117 | page.tag_list.add("event") if flags.attributes['calendar'] | 118 | page.tag_list.add("event") if flags.attributes['calendar'] |
| 118 | page.tag_list.add("pressemitteilung") if flags.attributes['pm'] | 119 | page.tag_list.add("pressemitteilung") if flags.attributes['pm'] |
| 120 | |||
| 121 | if flags.attributes['calendar'] | ||
| 122 | cal = Vpim::Icalendar.create2 | ||
| 123 | |||
| 124 | dtstart = xhtml.elements['ical:DTSTART'] | ||
| 125 | dtisdate = dtstart.attributes['VALUE'] | ||
| 126 | raise "DTSTART not present in event" unless dtstart | ||
| 127 | if dtisdate && dtisdate == 'DATE' | ||
| 128 | dtstart = dtstart.text.to_date | ||
| 129 | else | ||
| 130 | dtstart = dtstart.text.to_time | ||
| 131 | end | ||
| 132 | |||
| 133 | dtend = xhtml.elements['ical:DTEND'] | ||
| 134 | dtisdate = dtend.attributes['VALUE'] if dtend | ||
| 135 | duration = xhtml.elements['ical:DURATION'] | ||
| 136 | puts "WARNING: Neither DTEND nor DURATION present in event" unless dtend || duration | ||
| 137 | # raise "Both DTEND and DURATION present in event" if dtend && duration | ||
| 138 | if dtend | ||
| 139 | if dtisdate && dtisdate == 'DATE' | ||
| 140 | dtend = dtend.text.to_date | ||
| 141 | else | ||
| 142 | dtend = dtend.text.to_time | ||
| 143 | end | ||
| 144 | end | ||
| 145 | duration = duration.text if duration | ||
| 146 | |||
| 147 | location = xhtml.elements['ical:LOCATION'] | ||
| 148 | localtrep = location.attributes['ALTREP'] if location | ||
| 149 | location = location.text if location | ||
| 150 | |||
| 151 | geo = xhtml.elements['ical:GEO'] | ||
| 152 | geo = geo.text if geo | ||
| 153 | |||
| 154 | if( rrule = xhtml.elements['ical:RRULE'] ) | ||
| 155 | rrtxt = '' | ||
| 156 | rrule.each_element( ) { |subrule| | ||
| 157 | rrtxt += subrule.name + '=' + subrule.text + ';' | ||
| 158 | } | ||
| 159 | rrtxt.chomp!(';') | ||
| 160 | end | ||
| 161 | |||
| 162 | hash = { 'CREATED' => page.published_at } | ||
| 163 | hash[ 'DTEND' ] = dtend if dtend | ||
| 164 | hash[ 'DURATION' ] = duration if duration | ||
| 165 | hash[ 'LOCATION' ] = location if location | ||
| 166 | hash[ 'GEO' ] = geo if geo | ||
| 167 | hash[ 'URL' ] = localtrep if localtrep | ||
| 168 | hash[ 'RRULE' ] = rrtxt if rrtxt | ||
| 169 | |||
| 170 | xevent = Vpim::Icalendar::Vevent.create( dtstart, hash ) | ||
| 171 | cal.push( xevent ) | ||
| 172 | puts cal.to_s | ||
| 173 | |||
| 174 | end | ||
| 119 | end | 175 | end |
| 120 | 176 | ||
| 121 | page.save! | 177 | page.save! |
| 122 | 178 | ||
| 123 | if node.head.nil? && page | 179 | if node.head.nil? && page |
| 124 | node.head = page | 180 | node.head = page |
| 125 | node.draft = nil | 181 | node.draft = nil |
| @@ -173,4 +229,4 @@ class UpdateImporter | |||
| 173 | element | 229 | element |
| 174 | end | 230 | end |
| 175 | 231 | ||
| 176 | end \ No newline at end of file | 232 | end |
