Skip to content

Instantly share code, notes, and snippets.

@kmorey
Created January 31, 2016 23:37
Show Gist options
  • Save kmorey/ce373a2efecf75748f7f to your computer and use it in GitHub Desktop.
Save kmorey/ce373a2efecf75748f7f to your computer and use it in GitHub Desktop.
Battlefront Stats Dumper
# using network monitor on the battlefront stats page and grab the response of
# https://api.battlefront.dice.se/jsonrpc/whiteshark/pc/api?UserStats.getUserStats
# for the user you want and paste it to a json file
# Usage: python bf.py <stats.json>
import json
import sys
filename = sys.argv[1]
with open(filename, 'r') as fp:
x = json.load(fp)
try:
class StatsDumper:
@staticmethod
def dump_multiplayer_levels(d):
pass
# print json.dumps(d, indent=2)
@staticmethod
def dump_accomplishments(d):
pass
@staticmethod
def dump_diorama(d):
print "Diorama ({0}/{1})".format(d['diorama']['stats']['completed'], d['diorama']['stats']['total'])
for item in d['diorama']['items']:
print item['title'], "({0})".format(item['code'])
print " ", item['description']
for obj in item['stats']:
print " ", obj['statCounter']['title'], obj['statCounter']['value']
# print json.dumps(d, indent=2)
@staticmethod
def dump_game_modes(d):
pass
# print json.dumps(d, indent=2)
@staticmethod
def dump_weapons(d):
StatsDumper.dump_vehicles(d)
# print json.dumps(d, indent=2)
# exit()
@staticmethod
def dump_vehicles(d):
for k, v in d.items():
print k
for k2, obj in v.items():
if k2 == "items":
for foo in obj:
print " ", foo['title']
for K in foo.keys():
if isinstance(foo.get(K), dict) and foo.get(K).has_key("value"):
print " ", foo[K]['title'], foo[K]['value'], foo[K]['id']
sd = StatsDumper()
for k in x['result'].keys():
print "=" * 40
try:
fn = getattr(sd, "dump_{0}".format(k))
fn(x['result'][k])
except AttributeError:
print "!!! missing handler function dump_{0}".format(k)
#print json.dumps(x, indent=2)
except:
print x['result'].keys()
raise
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment