2

我在 GooglePlay 中发布了一份我正在迁移到华为 AppGallery 的文章。由于我的应用程序有大约 100 个应用程序内产品,我想以某种(半)自动方式迁移它们。

我做了一些研究,我注意到两个平台都提供导入/导出选项。但是它们确实有很大不同 - 首先是文件格式(Google 的 CSV,华为的 Excel),其次是数据结构和导出的参数类型,例如 Google CSV 在此处输入图像描述 Huawei AppGallery 在此处输入图像描述

我所有的产品都是消耗品(没有订阅)。

有没有快速迁移的方法?

4

1 回答 1

1

我最近也有类似的需求,我最终编写了 ruby​​ 脚本来实现这一点。

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]}"

` 您需要以下 gem 包才能成功运行脚本

-csv
-fileutils
-write_xlsx

现在直接转到你的主目录,你有你的脚本文件并导出了 google csv,然后在命令提示符下运行以下命令: ruby [your_script_name].rb -s GoogleExportedCSV.csv -d HAGExcel.xlsx -c GB-GBP

这应该可以解决问题!

于 2020-06-26T07:41:49.437 回答