Permalink
Browse files

Updated upload_news to better handle publish dates. Set edition equal…

… to the last digits of the catalog.
  • Loading branch information...
1 parent 9f542db commit 474af3f0073378156dc1701a6a2d0d90e39b6832 @jeremyf committed May 26, 2011
Showing with 8 additions and 8 deletions.
  1. +8 −8 lib/upload_news.rb
View
16 lib/upload_news.rb
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
require 'yaml'
require 'active_support/core_ext/hash'
+require 'active_support/time'
require 'rest_client'
require 'highline'
@@ -20,14 +21,11 @@ def password
def parse_time(year, month, dayish)
begin
- published_at = Time.local(year, month, dayish)
- rescue ArgumentError => e
- dayish -= 1
- if dayish > 0
- retry
- else
- raise e
+ if new_time = Time.local(year.to_i, month.to_i, dayish.to_i, 0, 0, dayish.to_i)
+ return new_time
end
+ rescue ArgumentError => e
+ return Time.local(year.to_i, month.to_i, 1).end_of_month.beginning_of_day + dayish.to_i
end
end
@@ -36,7 +34,9 @@ def parse_time(year, month, dayish)
attributes = YAML.load_file(filename).stringify_keys
if attributes['conductor_path'].nil?
catalog_id = attributes['catalog_id'].to_s.strip
+ edition_number = nil
if catalog_id =~ /\A(\d\d\d\d)\.(\d\d)\.(\d\d)\Z/
+ edition_number = $3
published_at = parse_time($1.to_i,$2.to_i,$3.to_i)
end
params = {}
@@ -49,7 +49,7 @@ def parse_time(year, month, dayish)
params['news']['published_at'] = published_at
params['news']['custom_author_name'] = attributes['authors']
params['news']['metum_attributes']['keys'] << 'edition'
- params['news']['metum_attributes']['data'] << catalog_id
+ params['news']['metum_attributes']['data'] << edition_number
params['news']['metum_attributes']['keys'] << 'reviewers'
params['news']['metum_attributes']['data'] << attributes['reviewer']
params['news']['metum_attributes']['keys'] << 'bibliography'

0 comments on commit 474af3f

Please sign in to comment.