Created
August 1, 2019 12:12
-
-
Save PrimaryFeather/c1694a2be8727929b73b3c26028a5c77 to your computer and use it in GitHub Desktop.
Dumps all Flox players as JSON files to a folder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.