adops_report_scrapper 0.2.35 → 0.2.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9a80c798f022a79269546a5f1fb2f8e99921b06
4
- data.tar.gz: 37cf1e17c2ad5e7837ff1e90936015fd5b232aaf
3
+ metadata.gz: 4cf064a3b734f43507cd24f2ad6b904bccf1225d
4
+ data.tar.gz: cec38e250b5689ef69913a791e05e16265419874
5
5
  SHA512:
6
- metadata.gz: 3adf61abd8e28530eb3d5bcf1ff16d6c799d135c16bf03096a1a978e5e6e2dd2885c27753fdb1e60469d2e988fbb82a5d2c977811a094cc39a74000acde1438e
7
- data.tar.gz: 3053718c47f72ee09e5f1d0bd5d43145a46cdd398ebe1c71916bff8ebc0157d8eb2d0fbe3fe521c7fc7fff1c9f5a23dd32b38104628dbaaf1f1c1d2d995f57d9
6
+ metadata.gz: 97358fa3667fb4ebf77be5b4269b5b800ede5267f09b447541e914df6b60f8136995a8c2a873d898b1e49f751eb86a69851e5faa2482de5f516d749365736213
7
+ data.tar.gz: 1f2e15de0eba6d7b48a71e6fb10927f40f64c4b374733cd5b1987d1b02adf1cbfeabd8e4e3c8b13436f34ab2227697e2ab2d34807e57cae40a32b91394473d6f
data/CHANGELOG CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.2.37
4
+ add ignore_receive_date option for email client to ignore the email receive date when searching for a report
5
+
6
+ ## 0.2.36
7
+ add header_first_cell option for email client to match the first cell of a row and find the header/starting row of the actual data
8
+
3
9
  ## 0.2.35
4
10
  implement indexexchange
5
11
 
data/Rakefile CHANGED
@@ -231,6 +231,11 @@ task :indexexchange do
231
231
  save_as_csv :indexexchange, :indexexchange
232
232
  end
233
233
 
234
+ desc 'Collect yume data'
235
+ task :yume do
236
+ save_as_csv :yume, :email
237
+ end
238
+
234
239
  def date
235
240
  @date ||= ENV['date'].nil? ? Date.today - 1 : Date.today - ENV['date'].to_i
236
241
  end
@@ -22,7 +22,9 @@ class AdopsReportScrapper::EmailClient < AdopsReportScrapper::BaseClient
22
22
  @imap_ssl = @options['imap_ssl']
23
23
  @title = @options['title'] # supports data macro e.g. `XXX Report %Y-%m-%d` will match XXX Report `2017-04-26`
24
24
  @date_column = @options['date_column'] # optional. supports data macro e.g. `0||%Y-%m-%d` will match rows that has `2017-04-26` for their first column
25
+ @header_first_cell = @options['header_first_cell'] # optional. It will try to match the first cell text, and treat the matched row as header, ignoring all the rows above. By default, it will take the first row as header.
25
26
  @imap_ssl_verify = @options['imap_ssl_verify'].nil? ? true : @options['imap_ssl_verify']
27
+ @ignore_receive_date = @options['ignore_receive_date'].nil? ? false : @options['ignore_receive_date']
26
28
  end
27
29
 
28
30
  def before_quit_with_error
@@ -36,7 +38,10 @@ class AdopsReportScrapper::EmailClient < AdopsReportScrapper::BaseClient
36
38
  imap = Net::IMAP.new(@imap_server, @imap_port, @imap_ssl, nil, @imap_ssl_verify)
37
39
  imap.login(@login, @secret)
38
40
  imap.select('INBOX')
39
- report_email_ids = imap.search(['ON', email_received_date, 'SUBJECT', title])
41
+ search_condition = []
42
+ search_condition += ['ON', email_received_date] unless @ignore_receive_date
43
+ search_condition += ['SUBJECT', title]
44
+ report_email_ids = imap.search search_condition
40
45
  if report_email_ids.count == 0
41
46
  imap.logout
42
47
  imap.disconnect
@@ -65,7 +70,19 @@ class AdopsReportScrapper::EmailClient < AdopsReportScrapper::BaseClient
65
70
  column_index, date_format_str = @date_column.split('||')
66
71
  column_index = column_index.to_i
67
72
  date_str = @date.strftime(date_format_str)
68
- header = @data.shift
73
+ header = nil
74
+ if @header_first_cell
75
+ while !@data.empty?
76
+ row = @data.shift
77
+ if @header_first_cell == row[0]
78
+ header = row
79
+ break
80
+ end
81
+ fail 'empty report' if @data.length == 0
82
+ end
83
+ else
84
+ header = @data.shift
85
+ end
69
86
  @data = @data.select { |row| row[column_index] == date_str }
70
87
  @data.unshift header
71
88
  end
@@ -1,3 +1,3 @@
1
1
  module AdopsReportScrapper
2
- VERSION = "0.2.35"
2
+ VERSION = "0.2.37"
3
3
  end
data/secret.sample.yml CHANGED
@@ -147,6 +147,7 @@ mediabong:
147
147
  imap_ssl_verify: false
148
148
  title: XXX Report
149
149
  date_column: 1||%Y-%m-%d
150
+ ignore_receive_date: true/false
150
151
  anyclip:
151
152
  login: ------
152
153
  secret: ------
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adops_report_scrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.35
4
+ version: 0.2.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stayman Hou
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-18 00:00:00.000000000 Z
11
+ date: 2017-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient