argos-ruby 1.1.3 → 1.1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/lib/argos.rb +1 -1
  3. data/lib/argos/download.rb +84 -0
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmM0NDJiNWVjNDNjMWRhYTI4MmNjYWY2NTQ5ZTAwOWQwMjY5YTFjNA==
4
+ YzBiNzk2MjU0YWQ0NGViYzk2ZjMzMjZhMTBjYjgzNjY4M2U2MzdkMg==
5
5
  data.tar.gz: !binary |-
6
- MzBiY2Q2MzYyOGU2NmY3NTNjMjE3MDhlNzYzMjk4YTNjODc2MDU4Yg==
6
+ ZjNhYTliZDM2ZWNjOTg4OWFlMzEyYjZiMmYzMjVkZDY0MDc4MmUzMA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmM4ZmI1N2EzMzAxODhhZWE4NTk1MmMyYTAyNGM4ZDNkZWZiOWI4YTRiNDg5
10
- MTc3OTdlYTkyMmY2NGJhMTk1OWFlMDc4OTEyYjA4MTMzNzI3OWFlNTEyYWM0
11
- MjcyMjNjNTAyNzQxMDAwOTZkNTVmMzJmZmZhMWM3ZWZjZGZhYzk=
9
+ ZDI3YzNiYTlhMmY2MmU4NGMwOTQxZThjNzc5NjgwZjc2NDAzNjgxNzYzNDQw
10
+ ZTVmZWM5ZTc3ZmM0OWNkZDE2ZTNiZGI0ZTc2NzFmY2UzOTM5ZGRjYWYxOGM4
11
+ NmVmOWU3ODAxZDdlOWVkNmJlODg3MDVhNGJmMWQ0NTA1NzJlZjY=
12
12
  data.tar.gz: !binary |-
13
- MDcyMTZkMmYyNDVkOTdmZDY5YTBhZDk4MjkzZDc5NWRkNTY1ZTMwZWVlZTMz
14
- OGQ2ZThiMDhiYWNmYjViNjhhZjk4YTA2YTkwYzc5OGVlYTczYmQ1YzdjZDQ4
15
- OWYyM2E4M2IyMTNiNzI4ZDk2YWM1ODVlNTQ1MTAzYzBhZjU3NmE=
13
+ MjlkNmM4MDhmMDZhNGIwY2FlNWU2MTYxNmQ1MWJlMTUxNDEyZDYxMjY0MThh
14
+ MmZjNGU3NTgyOGE4MjZhNTUwNGVlZDI1OTYyYjEwYjQ3MmQxMWIxMWE0NTQz
15
+ NjQyYWI4Y2EwNDFjMWUwNzg1MjEyMjExZGUzOWZjYTdiMzQ3NGI=
data/lib/argos.rb CHANGED
@@ -25,7 +25,7 @@ require_relative "argos/download"
25
25
  #
26
26
  # For information about Argos, see: http://www.argos-system.org
27
27
  module Argos
28
- VERSION = "1.1.3"
28
+ VERSION = "1.1.3.1"
29
29
 
30
30
  def self.library_version
31
31
  "argos-ruby-#{VERSION}"
@@ -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