argos-ruby 1.1.3 → 1.1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/argos.rb +1 -1
- data/lib/argos/download.rb +84 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzBiNzk2MjU0YWQ0NGViYzk2ZjMzMjZhMTBjYjgzNjY4M2U2MzdkMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjNhYTliZDM2ZWNjOTg4OWFlMzEyYjZiMmYzMjVkZDY0MDc4MmUzMA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDI3YzNiYTlhMmY2MmU4NGMwOTQxZThjNzc5NjgwZjc2NDAzNjgxNzYzNDQw
|
10
|
+
ZTVmZWM5ZTc3ZmM0OWNkZDE2ZTNiZGI0ZTc2NzFmY2UzOTM5ZGRjYWYxOGM4
|
11
|
+
NmVmOWU3ODAxZDdlOWVkNmJlODg3MDVhNGJmMWQ0NTA1NzJlZjY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjlkNmM4MDhmMDZhNGIwY2FlNWU2MTYxNmQ1MWJlMTUxNDEyZDYxMjY0MThh
|
14
|
+
MmZjNGU3NTgyOGE4MjZhNTUwNGVlZDI1OTYyYjEwYjQ3MmQxMWIxMWE0NTQz
|
15
|
+
NjQyYWI4Y2EwNDFjMWUwNzg1MjEyMjExZGUzOWZjYTdiMzQ3NGI=
|
data/lib/argos.rb
CHANGED
@@ -0,0 +1,84 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "logger"
|
3
|
+
require "time"
|
4
|
+
|
5
|
+
module Argos
|
6
|
+
|
7
|
+
# Download utility class to take the strain out of downloading and
|
8
|
+
# archiving Argos XML and CSV for multiple users, programs and platforms.
|
9
|
+
#
|
10
|
+
# Downlods the last 20 days, one day at a time, and stores data in the following structure
|
11
|
+
# /{archive}/{year}/program-{programNumber}/platform-{platformId}/argos-{YYYY-MM-DD}-platform-{platformId}.[xml|csv]
|
12
|
+
#
|
13
|
+
# Command line:
|
14
|
+
# $ ./bin/argos-soap --download /mnt/tracking/ws-argos.cls.fr --username=xyz --password=123
|
15
|
+
|
16
|
+
class Download
|
17
|
+
|
18
|
+
def self.download(username, password, archive, log, days=20)
|
19
|
+
|
20
|
+
soap = Argos::Soap.new({username: username, password: password})
|
21
|
+
soap.log = log
|
22
|
+
|
23
|
+
programs = soap.programs
|
24
|
+
|
25
|
+
year = DateTime.now.year
|
26
|
+
|
27
|
+
soap.getPlatformList["data"]["program"].each do |program|
|
28
|
+
programNumber = program["programNumber"]
|
29
|
+
soap.programNumber = programNumber
|
30
|
+
|
31
|
+
platforms = soap.platforms
|
32
|
+
log.debug "Program: #{program["programNumber"]}, #{platforms.size} platform(s)"
|
33
|
+
|
34
|
+
program["platform"].select {|platform|
|
35
|
+
|
36
|
+
lastCollectDate = DateTime.parse(platform["lastCollectDate"])
|
37
|
+
lastLocationDate = DateTime.parse(platform["lastLocationDate"])
|
38
|
+
|
39
|
+
twentydays = DateTime.parse((Date.today-20).to_s)
|
40
|
+
|
41
|
+
(lastCollectDate > twentydays or lastLocationDate > twentydays)
|
42
|
+
|
43
|
+
}.each_with_index do | platform, idx |
|
44
|
+
|
45
|
+
|
46
|
+
platformId = platform["platformId"]
|
47
|
+
soap.platformId = platformId
|
48
|
+
|
49
|
+
log.debug "Program: #{programNumber}, platform: #{platformId}, lastCollectDate: #{platform["lastCollectDate"]}"
|
50
|
+
|
51
|
+
20.downto(1) do |daysago|
|
52
|
+
|
53
|
+
date = Date.today-daysago
|
54
|
+
|
55
|
+
destination = "#{archive}/#{year}/program-#{programNumber}/platform-#{platformId}"
|
56
|
+
|
57
|
+
begin
|
58
|
+
soap.period = {startDate: "#{date}T00:00:00Z", endDate: "#{date}T23:59:59.999Z"}
|
59
|
+
soap.getXml
|
60
|
+
|
61
|
+
|
62
|
+
FileUtils.mkdir_p(destination)
|
63
|
+
filename = destination+"/argos-#{date}-platform-#{platformId}.xml"
|
64
|
+
|
65
|
+
File.open(filename, "wb") { |file| file.write(soap.xml)}
|
66
|
+
log.debug "Saved #{filename}"
|
67
|
+
|
68
|
+
soap.getCsv
|
69
|
+
|
70
|
+
File.open(filename.gsub(/xml$/, "csv"), "wb") { |file| file.write(soap.text)}
|
71
|
+
|
72
|
+
rescue Argos::NodataException
|
73
|
+
# noop
|
74
|
+
rescue => e
|
75
|
+
log.error e
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: argos-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.3
|
4
|
+
version: 1.1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Espen Egeland
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- lib/argos/ascii.rb
|
47
47
|
- lib/argos/command.rb
|
48
48
|
- lib/argos/diag.rb
|
49
|
+
- lib/argos/download.rb
|
49
50
|
- lib/argos/ds.rb
|
50
51
|
- lib/argos/exception.rb
|
51
52
|
- lib/argos/soap.rb
|