Catch date error
This commit is contained in:
@@ -105,11 +105,15 @@ class Entsoe
|
|||||||
doc = Nokogiri::XML(URI.open(url))
|
doc = Nokogiri::XML(URI.open(url))
|
||||||
|
|
||||||
prices = doc.xpath('.//xmlns:Point').map{|p| parse_point(p)}
|
prices = doc.xpath('.//xmlns:Point').map{|p| parse_point(p)}
|
||||||
# get start_time (in UTC) from XML docment
|
begin
|
||||||
start_time = DateTime.parse(doc.xpath('.//xmlns:period.timeInterval//xmlns:start').text)
|
# get start_time (in UTC) from XML docment
|
||||||
|
start_time = DateTime.parse(doc.xpath('.//xmlns:period.timeInterval//xmlns:start').text)
|
||||||
|
|
||||||
#returns a hash with keys formatted "yyyy-mm-dd hr" and values price (per kwh)
|
#returns a hash with keys formatted "yyyy-mm-dd hr" and values price (per kwh)
|
||||||
# <position> tag runs from 1-24. We need hours from 00-23, therefore substracting 1
|
# <position> tag runs from 1-24. We need hours from 00-23, therefore substracting 1
|
||||||
prices.map{|p| [start_time.advance(hours: (p[0]-1)), p[1]]}.to_h
|
prices.map{|p| [start_time.advance(hours: (p[0]-1)), p[1]]}.to_h
|
||||||
|
rescue Date::Error => e
|
||||||
|
p e.message
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user