Last active
December 27, 2015 01:19
-
-
Save ragzilla/7244125 to your computer and use it in GitHub Desktop.
quick battlefield 4 stats fetch script
This file contains 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/python | |
from urllib2 import Request, urlopen | |
from sys import exit, argv | |
from simplejson import loads | |
from pprint import pprint | |
if len(argv) != 2: exit(1) | |
h = { 'X-AjaxNavigation': '1', 'User-Agent': 'urllib/2.7 - user@email.com', } | |
rq = Request('https://battlelog.battlefield.com/bf4/user/' + argv[1] + '/', None, h) | |
r = urlopen(rq) | |
if r.getcode() != 200: exit(1) | |
c = loads(r.read())['context'] | |
r.close() | |
del r | |
pId = None | |
if 'soldiersBox' not in c.keys(): exit(1) | |
for s in c['soldiersBox']: | |
if s['game'] != 2048: continue | |
pId = s['persona']['personaId'] | |
if pId == None: exit(1) | |
rq = Request('https://battlelog.battlefield.com/bf4/warsawoverviewpopulate/'+ pId +'/1/', None, h) | |
r = urlopen(rq) | |
if r.getcode() != 200: exit(1) | |
s = loads(r.read())['data'] | |
r.close() | |
del r | |
if 'overviewStats' not in s.keys(): exit(1) | |
s = s['overviewStats'] | |
print ' Rank:',s['rank'] | |
print 'Score:', s['score'] | |
print 'Skill:',s['skill'] | |
print ' SPM:',s['scorePerMinute'] | |
print ' K/D:',s['kills'],'/',s['deaths'],' (',s['kdRatio'],')' | |
print ' W/L:',s['numWins'],'/',s['numLosses'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment