Skip to content

Instantly share code, notes, and snippets.

@PrimaryFeather
Created August 1, 2019 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrimaryFeather/c1694a2be8727929b73b3c26028a5c77 to your computer and use it in GitHub Desktop.
Save PrimaryFeather/c1694a2be8727929b73b3c26028a5c77 to your computer and use it in GitHub Desktop.
Dumps all Flox players as JSON files to a folder.
#!/usr/bin/env ruby
require 'flox'
require 'fileutils'
GAME_ID = 'xxx'
GAME_KEY = 'yyy'
HERO_KEY = 'zzz'
OUT_FOLDER = 'flox-players'
STEP_SIZE = 50
offset = 0
step = 0
player_count = 0
flox = Flox.new(GAME_ID, GAME_KEY)
flox.login_with_key(HERO_KEY)
FileUtils.mkdir_p OUT_FOLDER
query = Flox::Query.new(:Player)
loop do
query.limit = STEP_SIZE
query.offset = STEP_SIZE * step
results = flox.find_entities query
results.each do |player|
File.write("#{OUT_FOLDER}/#{player.id}.json",
JSON.pretty_generate(player))
end
player_count += results.count
if results.empty? then break
else
puts "Step #{step} - found #{results.count} players"
step += 1
end
end
puts "Found #{player_count} players."
@PrimaryFeather
Copy link
Author

Warning: this loads the players sequentially, so it can take a long time if you've got a big player database.
In that case, you should rather use the AS3 API, which loads all entities found by a single "query.find" in parallel. Either way, don't make STEP_SIZE too big.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment