-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBackup.rb
67 lines (57 loc) · 1.55 KB
/
Backup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require "spaceship"
require 'json'
require 'fileutils'
Spaceship::Tunes.login(ARGV[0])
def save_to_json(hash_data, filename)
File.open(filename,"w") do |f|
f.write(JSON.pretty_generate(hash_data))
end
end
def get_app_info (app)
app_info = Hash.new
# keywords, description
v = nil
if app.live_version
v = app.live_version
elsif app.edit_version
v = app.edit_version
end
fields = ['keywords', 'description', 'promotional_text']
fields.each do |field|
app_attr = Hash.new
app_obj = v.send(field)
app_obj.original_array.collect do |current|
key = current['language'] ||= current['localeCode']
app_attr[key] = current.fetch(app_obj.identifier, {}).fetch('value')
end
app_info[field] = app_attr
end
# name, subtitle
d = app.details
fields = ['name', 'subtitle']
fields.each do |field|
app_attr = Hash.new
app_obj = d.send(field)
app_obj.original_array.collect do |current|
key = current['language'] ||= current['localeCode']
app_attr[key] = current.fetch(app_obj.identifier, {}).fetch('value')
end
app_info[field] = app_attr
end
return app_info
end
def create_dir_if_not_exist (dirname)
unless File.directory?(dirname)
FileUtils.mkdir_p(dirname)
end
end
create_dir_if_not_exist("data")
Spaceship::Tunes::Application.all.collect do |app|
puts "Processing ... #{app.name}"
app_data = get_app_info(app)
save_to_json(app_data, "data/#{app.bundle_id}.json")
end
# app = Spaceship::Tunes::Application.find("com.ittus.swingbattle")
# app_data = get_app_info(app)
# save_to_json(app_data, "#{app.bundle_id}.json")
puts "Done!"