I have an published in GooglePlay that I am migrating to Huawei AppGallery. Since my app have about 100 In-app products I would like to migrate them in some (semi)-automatic way.
I have done some research and I noticed that both platform offer import/export option. However they do differ quite a lot - firstly in file format (CSV for Google, Excel for Huawei), secondly in data structure and type of parameters being exported, e.g. Google CSV Huawei AppGallery
ALl my products are consumables (no subscritpions).
Is there a fast way to do the migration?
I also had similar need recently and I ended up writing ruby script to achieve this.
require 'fileutils'
require "csv"
require 'rubygems'
require 'write_xlsx'
require 'optparse'
$DEBUG_INFO = false
XLSX_PRODUCT_ID_COLUMN_INDEX = 0
XLSX_PRODUCT_TYPE_COLUMN_INDEX = 1
XLSX_LANGUAGE_COLUMN_INDEX = 2
XLSX_CURRENCY_COLUMN_INDEX = 3
XLSX_PRICE_COLUMN_INDEX = 4
XLSX_SUBPERIOD_COLUMN_INDEX = 5
XLSX_HEADER_ROW = ['productId', 'productType', 'languages', 'currency', 'price', 'subPeriod']
XLSX_PRODUCT_ID_DESCRIPTION = 'The product ID must begin with a letter or number, and contains only letters (A-Z, a-z), numbers (0-9), underlines (_) or full stops (.)'
XLSX_PRODUCT_TYPE_DESCRIPTION = '0:Consumables 3:Non-consumables 2:Auto-renewable subscriptions(Product type cannot be edited once saved.)'
XLSX_LANGUAGES_DESCRIPTION = 'The product name must be a string of 1-55 characters, and the product description must be between 1-100 characters.The product name and the product description can not use use the following special characters ><\'"&$)%+\/#*,^|:. Enter a language in the format of \"Language type > Product name > Product description\". Separate different languages with a comma '
XLSX_CURRENCY_DESCRIPTION = 'The country and currency type used for pricing a product, are in the format: "Country - currency type".'
XLSX_PRICE_DESCRIPTION = 'Product price. Retain two decimal places, for example, 1.99. The system converts the entered price into the target price using the entered currency type and exchange rate, and will round the last digit of the price to 0, 6, or 9. Click this cell to view the Huawei special country currency requirements.'
XLSX_SUBPERIOD_DESCRIPTION = 'It is available only for a subscription. Supported values are [1 week, 1 month, 2 months, 3 months, 6 months, 1 year]'
XLSX_DESCRIPTION_ROW = [XLSX_PRODUCT_ID_DESCRIPTION, XLSX_PRODUCT_TYPE_DESCRIPTION, XLSX_LANGUAGES_DESCRIPTION, XLSX_CURRENCY_DESCRIPTION, XLSX_PRICE_DESCRIPTION, XLSX_SUBPERIOD_DESCRIPTION]
MICROUNIT_TO_UNIT_RATE = 1_000_000
CONSUMABLE_PRODUCT_TYPE = 0
AUTO_RENEWABLE_SUBSCRIPTION = 2
NON_CONSUMABLE_PRODUCT_TYPE = 3
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: example migrate_IAP_to_HAG.rb –s GoogleExampleCSV.csv –d HAGExcel.xlsx –c GB-GBP"
opts.on("-s", "--source_path ", "path to CSV file with Google IAP ") do |v|
options[:src_path] = v
puts "options[:src_path] = #{options[:src_path]}" if $DEBUG_INFO
end
opts.on("-d", "--destination_path ", "path where Excel with Huawei AppGallery products will be created ") do |v|
options[:dest_path] = v
puts "options[:dest_path] = #{options[:dest_path]}" if $DEBUG_INFO
end
opts.on("-c", "--currency ", "currency used as default for Google Play app, e.g. GB-GBP") do |v|
options[:currency] = v
puts "options[:currency] = #{options[:currency]}" if $DEBUG_INFO
end
end.parse!
#verify input
if not File.file?(options[:src_path])
raise "Input CSV file #{options[:src_path]} does not exists - please check if you provided right path"
end
destination_directory = File.dirname( options[:dest_path])
if not File.directory?(destination_directory)
puts "Directory ##{destination_directory} doesn't exist. Creating directory"
unless File.directory?(dirname)
FileUtils.mkdir_p(dirname)
end
end
puts 'Transforming Google Play CSV file into Huawei AppGallery Excel with IAP products'
#open destination file for editing
workbook = WriteXLSX.new( options[:dest_path])
worksheet = workbook.add_worksheet 'Preparing imported products'
def change_translation_format(google_translation)
langauge =''
title = ''
description = ''
result = ''
#remove not allowed characters ><'"&$)%+\/#*,^|:.
google_translation.gsub!(/[!><'"&$)%+\/#*,^|:.]/,'')
google_translation.split(';').each_with_index {|val, index|
case index%3
when 0 #item locale (language)
language = val.gsub(/[_]/, '-').strip #change en_US to en-US, strip removes whitespace from begining and end
result << language << '>'
when 1 # item description
title = val.strip
result << title << '>'
when 2 # item description
description = val.strip
result << description << ','
end
}
print "result = #{result}" if $DEBUG_INFO
return result
end
#Copy first 2 rows from Product Import Template
#write Excel headers in 1st row (starting from cell (0,0)
worksheet.write_row(0, 0, XLSX_HEADER_ROW)
#write Excel with header descriptions in 2nd row (starting from cell (1,0)
format = workbook.add_format()
format.set_text_wrap()
format.set_shrink()
worksheet.write_row(1, 0, XLSX_DESCRIPTION_ROW, format)
#start with 3rd (index starts from 0 so actually 2) row since first is header and second is with general information
excel_row_iterator = 2
number_of_products = 0
#Read Google CVS file and write data into Excel
CSV.foreach(options[:src_path], headers: true) do |row|
puts "excel_row_iterator = #{excel_row_iterator}, row = #{row}" if $DEBUG_INFO
product_id = row['Product ID']
print "product_id = #{product_id}" if $DEBUG_INFO
worksheet.write(excel_row_iterator, XLSX_PRODUCT_ID_COLUMN_INDEX, product_id)
worksheet.write(excel_row_iterator, XLSX_PRODUCT_TYPE_COLUMN_INDEX, CONSUMABLE_PRODUCT_TYPE)
google_translation_format = row['Locale; Title; Description']
print "Locale = #{google_translation_format}" if $DEBUG_INFO
translation = change_translation_format(google_translation_format)
worksheet.write(excel_row_iterator, XLSX_LANGUAGE_COLUMN_INDEX, translation)
worksheet.write(excel_row_iterator, XLSX_CURRENCY_COLUMN_INDEX, options[:currency])
price_microunits = row['Price'].to_f
print "price_microunits = #{price_microunits}" if $DEBUG_INFO
price = price_microunits / MICROUNIT_TO_UNIT_RATE
worksheet.write(excel_row_iterator, XLSX_PRICE_COLUMN_INDEX, price)
number_of_products += 1
excel_row_iterator += 1
end
puts ""
puts ""
puts "Transformation done, total IAP products number = #{number_of_products}"
workbook.close
puts "File saved as #{options[:dest_path]}"
` You will require following gem packages to run script successfully
-csv
-fileutils
-write_xlsx
Now go to your main directly where you have your script file and exported google csv then run following command in command prompt:
ruby [your_script_name].rb -s GoogleExportedCSV.csv -d HAGExcel.xlsx -c GB-GBP
This should do the trick!