applocale 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/applocale/Core/GoogleHepler/google_helper.rb +38 -5
- data/lib/applocale/Core/ParseCSV/parse_csv.rb +17 -5
- data/lib/applocale/Core/setting.rb +8 -6
- data/lib/applocale/Util/config_util.rb +7 -2
- data/lib/applocale/Util/error_util.rb +10 -0
- data/lib/applocale/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0b2379061e419ebd39b78bcff31a60598ef063f
|
4
|
+
data.tar.gz: 83523c243bfba37160fd902940a89338ff3318ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf7f2cac8b836a140ec030d7c701c92de0b66f313ccbb3d563524901cf41710f5856954a7477788f4b112f5d48f842f7ffeb44304920a58b93e9be91c6b393b9
|
7
|
+
data.tar.gz: 3f0d2b1f7879d12082c787a204e9b65fa8f5cfdc990641f686a4afb65b4e90849ee512802d3526e25393e1fab2bf11c46f46c3775dc64efd2ebcd10b78d50d32
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'google/apis/drive_v3'
|
2
|
+
require 'google/apis/sheets_v4'
|
2
3
|
require 'googleauth'
|
3
4
|
require 'googleauth/stores/file_token_store'
|
4
5
|
require 'fileutils'
|
@@ -46,13 +47,45 @@ module Applocale
|
|
46
47
|
authorization = authorize
|
47
48
|
begin
|
48
49
|
case export_format
|
49
|
-
|
50
|
-
|
50
|
+
when 'csv'
|
51
|
+
service = Google::Apis::SheetsV4::SheetsService.new
|
52
|
+
service.client_options.application_name = APPLICATION_NAME
|
53
|
+
service.authorization = authorization
|
54
|
+
sheets = service.get_spreadsheet(self.spreadsheet_id).sheets
|
55
|
+
sheetMap = {}
|
56
|
+
sheets.each do |sheet|
|
57
|
+
sheetMap[sheet.properties.title.to_s] = sheet.properties.sheet_id
|
58
|
+
end
|
59
|
+
|
60
|
+
index = 0
|
61
|
+
sheet_obj_list.each do |sheet_obj|
|
51
62
|
sheet_name = sheet_obj.sheetname
|
52
63
|
file_path = File.expand_path("#{sheet_name}.csv", export_to)
|
53
|
-
|
54
|
-
|
55
|
-
|
64
|
+
if sheetMap[sheet_name].nil?
|
65
|
+
ErrorUtil::SheetNotExist.new(sheet_name).raise
|
66
|
+
end
|
67
|
+
puts "to download sheet: #{sheet_name}"
|
68
|
+
if !sheet_obj.obj.use_export
|
69
|
+
link = "https://docs.google.com/spreadsheets/d/1kapxktmMI605BhStCNd6F4Hst1A3HuNEfA4945_Mqa0/gviz/tq?tqx=out:csv&sheet=#{sheet_name}&access_token=#{authorization.access_token}"
|
70
|
+
puts "https://docs.google.com/spreadsheets/d/1kapxktmMI605BhStCNd6F4Hst1A3HuNEfA4945_Mqa0/gviz/tq?tqx=out:csv&sheet=#{sheet_name}&access_token=xxxxx"
|
71
|
+
csv = open(link)
|
72
|
+
IO.copy_stream(csv, file_path)
|
73
|
+
else
|
74
|
+
if index % 3 == 0
|
75
|
+
puts "please wait ... "
|
76
|
+
sleep(5)
|
77
|
+
else
|
78
|
+
puts "please wait .. "
|
79
|
+
sleep(2)
|
80
|
+
end
|
81
|
+
link = "https://docs.google.com/spreadsheets/d/1kapxktmMI605BhStCNd6F4Hst1A3HuNEfA4945_Mqa0/export?format=csv&gid=#{sheetMap[sheet_name]}&access_token=#{authorization.access_token}"
|
82
|
+
puts "https://docs.google.com/spreadsheets/d/1kapxktmMI605BhStCNd6F4Hst1A3HuNEfA4945_Mqa0/export?format=csv&gid=#{sheetMap[sheet_name]}&access_token=xxxxx"
|
83
|
+
File.open(file_path, "wb") do |file|
|
84
|
+
file.write open(link).read
|
85
|
+
end
|
86
|
+
index = index + 1
|
87
|
+
end
|
88
|
+
end
|
56
89
|
when 'xlsx'
|
57
90
|
service = Google::Apis::DriveV3::DriveService.new
|
58
91
|
service.client_options.application_name = APPLICATION_NAME
|
@@ -47,6 +47,7 @@ module Applocale
|
|
47
47
|
next
|
48
48
|
end
|
49
49
|
rows = CSV.read(csv_path)
|
50
|
+
|
50
51
|
header = find_header(sheet_obj, rows)
|
51
52
|
sheet_content.header_rowno = header[:header_row_index]
|
52
53
|
sheet_content.keyStr_with_colno = header[:key_header_info]
|
@@ -84,19 +85,30 @@ module Applocale
|
|
84
85
|
sheet_language_list = sheet_info_obj.lang_headers
|
85
86
|
sheet_key_header = sheet_info_obj.key_header
|
86
87
|
|
87
|
-
header_row_index =
|
88
|
-
|
89
|
-
|
88
|
+
header_row_index = nil
|
89
|
+
|
90
|
+
rows.each_with_index {|row,index |
|
91
|
+
row.each do |rowValue|
|
92
|
+
if rowValue.to_s.strip == sheet_key_header.to_s
|
93
|
+
header_row_index = index
|
94
|
+
break
|
95
|
+
end
|
96
|
+
break if !header_row_index.nil?
|
97
|
+
end
|
98
|
+
}
|
90
99
|
|
91
100
|
header_row_info = rows[header_row_index] unless header_row_index.nil?
|
92
|
-
|
101
|
+
if header_row_info.nil?
|
102
|
+
raise "ParseCSVError: Header not found in sheet: #{sheet_name}"
|
103
|
+
end
|
104
|
+
header_column_index = header_row_info.index { |cell| cell.to_s.strip == sheet_key_header }
|
93
105
|
if header_row_index.nil? || header_column_index.nil?
|
94
106
|
raise "ParseCSVError: Header not found in sheet #{sheet_name}"
|
95
107
|
end
|
96
108
|
key_header_info = ParseModelModule::KeyStrWithColNo.new(sheet_key_header, header_column_index)
|
97
109
|
|
98
110
|
language_header_list = sheet_language_list.map do |key, value|
|
99
|
-
cell_index = header_row_info.index { |cell| cell == value }
|
111
|
+
cell_index = header_row_info.index { |cell| cell.to_s.strip == value }
|
100
112
|
cell_index.nil? ? nil : ParseModelModule::LangWithColNo.new(value, key, cell_index)
|
101
113
|
end.compact
|
102
114
|
unless language_header_list.length == sheet_language_list.length
|
@@ -97,29 +97,31 @@ module Applocale
|
|
97
97
|
end
|
98
98
|
|
99
99
|
class SheetInfoByHeader
|
100
|
-
attr_accessor :key_header, :lang_headers
|
100
|
+
attr_accessor :key_header, :lang_headers, :use_export
|
101
101
|
|
102
|
-
def initialize(key_header, lang_headers)
|
102
|
+
def initialize(key_header, lang_headers, use_export)
|
103
103
|
self.key_header = key_header
|
104
104
|
self.lang_headers = lang_headers
|
105
|
+
self.use_export = use_export
|
105
106
|
end
|
106
107
|
|
107
108
|
def to_s
|
108
|
-
return "key_header: #{self.key_header} | headers: #{self.lang_headers.to_s}"
|
109
|
+
return "key_header: #{self.key_header} | headers: #{self.lang_headers.to_s} | use_export: #{self.use_export}"
|
109
110
|
end
|
110
111
|
end
|
111
112
|
|
112
113
|
class SheetInfoByRow
|
113
|
-
attr_accessor :row, :key_col, :lang_cols
|
114
|
+
attr_accessor :row, :key_col, :lang_cols, :use_export
|
114
115
|
|
115
|
-
def initialize(row, key_col, lang_cols)
|
116
|
+
def initialize(row, key_col, lang_cols, use_export)
|
116
117
|
self.row = row
|
117
118
|
self.key_col = key_col
|
118
119
|
self.lang_cols = lang_cols
|
120
|
+
self.use_export = use_export
|
119
121
|
end
|
120
122
|
|
121
123
|
def to_s
|
122
|
-
return "row: #{self.row} | key_col: #{self.key_col} | lang_cols: #{self.lang_cols.to_s}"
|
124
|
+
return "row: #{self.row} | key_col: #{self.key_col} | lang_cols: #{self.lang_cols.to_s} | use_export: #{self.use_export}"
|
123
125
|
end
|
124
126
|
end
|
125
127
|
|
@@ -201,12 +201,17 @@ module Applocale
|
|
201
201
|
info_row = infos['row'].to_s.strip
|
202
202
|
info_key = infos['key'].to_s.strip
|
203
203
|
info_key_str = infos['key_str'].to_s.strip
|
204
|
+
info_use_export = infos["use_export"]
|
205
|
+
if info_use_export.nil?
|
206
|
+
info_use_export = "false"
|
207
|
+
end
|
208
|
+
info_use_export_bool = info_use_export.to_s.downcase == "true"
|
204
209
|
if info_row.length > 0 && info_key.length > 0
|
205
|
-
obj = SheetInfoByRow.new(info_row.to_i, info_key, lang_header_key_dict)
|
210
|
+
obj = SheetInfoByRow.new(info_row.to_i, info_key, lang_header_key_dict, info_use_export_bool)
|
206
211
|
sheet = Sheet.new(sheetname,obj)
|
207
212
|
setting.sheet_obj_list.push(sheet)
|
208
213
|
elsif info_key_str.length > 0
|
209
|
-
obj = SheetInfoByHeader.new(info_key_str, lang_header_key_dict)
|
214
|
+
obj = SheetInfoByHeader.new(info_key_str, lang_header_key_dict, info_use_export_bool)
|
210
215
|
sheet = Sheet.new(sheetname,obj)
|
211
216
|
setting.sheet_obj_list.push(sheet)
|
212
217
|
else
|
@@ -41,6 +41,16 @@ module Applocale
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
class SheetNotExist < CommonError
|
45
|
+
attr_accessor :sheetname
|
46
|
+
def initialize(sheetname)
|
47
|
+
@sheetname = sheetname
|
48
|
+
end
|
49
|
+
def message
|
50
|
+
"Can't find sheet: #{self.sheetname}"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
44
54
|
class CannotOpenXlsxFile < CommonError
|
45
55
|
attr_accessor :path
|
46
56
|
def initialize(path)
|
data/lib/applocale/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: applocale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kennix
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|