Last active
August 29, 2015 14:00
-
-
Save CRamsan/11165553 to your computer and use it in GitHub Desktop.
Added columns for time per class, accuracy, kdr and outfit size
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
import urllib.request | |
import json | |
import time | |
with open("data.csv", "a") as data: | |
#request = urllib.request.urlopen("http://census.soe.com/get/ps2:v2/character/?character_id=5428010618041058369&c:limit=100&c:resolve=stat_history,online_status,world&c:join=type:world^inject_at:server&c:join=type:faction^inject_at:faction") | |
five_minutes_ago = int(time.time()) - (15 * 60) | |
request = urllib.request.urlopen("http://census.soe.com/get/ps2:v2/character/?c:limit=500&c:resolve=stat_history,world,outfit,stat×.last_login=>1398389214") | |
characters = json.loads(request.read().decode('utf8'))['character_list'] | |
data.write("Name|Battle Rank|Minutes Played|Faction|Server|Score/Minute|K/D Ratio|Accuracy|Outfit Size|INF|LA|ENG|MED|HEA|MAX\n") | |
for character in characters: | |
name = character['name']['first'] | |
battleRank = character['battle_rank']['value'] | |
minutesPlayed = character['times']['minutes_played'] | |
faction = character['faction_id'] | |
server = character['world_id'] | |
sph = 0 | |
kdr = 0 | |
kills = 0 | |
deaths = 1 | |
stat_list = character['stats']['stat_history'] | |
for stat in stat_list: | |
if stat['stat_name'] == 'score': | |
sph = int(stat['all_time']) / int(minutesPlayed) | |
if stat['stat_name'] == 'kills': | |
kills = stat['all_time'] | |
if stat['stat_name'] == 'deaths': | |
deaths = stat['all_time'] | |
if deaths == '0': | |
deaths = 1 | |
kdr = int(kills)/int(deaths) | |
shots_fired = 0 | |
hit_count = 0 | |
infiltrator = 0 | |
light_assault = 0 | |
engineer = 0 | |
medic = 0 | |
heavy = 0 | |
mech = 0 | |
stats = character['stats']['stat'] | |
for stat in stats: | |
if stat['stat_name'] == 'fire_count': | |
shots_fired += int(stat['value_forever']) | |
if stat['stat_name'] == 'hit_count': | |
hit_count += int(stat['value_forever']) | |
if stat['stat_name'] == 'play_time': | |
if stat['profile_id'] == '1' or stat['profile_id'] == '17' or stat['profile_id'] == '10': | |
infiltrator += int(stat['value_forever'])/60 | |
elif stat['profile_id'] == '3' or stat['profile_id'] == '19' or stat['profile_id'] == '12': | |
light_assault += int(stat['value_forever'])/60 | |
elif stat['profile_id'] == '4' or stat['profile_id'] == '20' or stat['profile_id'] == '13': | |
medic += int(stat['value_forever'])/60 | |
elif stat['profile_id'] == '5' or stat['profile_id'] == '21' or stat['profile_id'] == '14': | |
engineer += int(stat['value_forever'])/60 | |
elif stat['profile_id'] == '6' or stat['profile_id'] == '22' or stat['profile_id'] == '15': | |
heavy += int(stat['value_forever'])/60 | |
elif stat['profile_id'] == '7' or stat['profile_id'] == '23' or stat['profile_id'] == '16': | |
mech += int(stat['value_forever'])/60 | |
accuracy = int(hit_count)/int(shots_fired) | |
if 'outfit' in character: | |
outfit_count = character['outfit']['member_count'] | |
else : | |
outfit_count = 0 | |
data.write(name + "|" + str(battleRank) + "|" + str(minutesPlayed) + "|" + str(faction) + "|" + str(server) + "|" + str(sph) + "|" + str(kdr) + "|" + str(accuracy) + "|" + str(outfit_count) + "|" + str(infiltrator) +"|" + str(light_assault) +"|" + str(engineer) +"|" + str(medic) +"|" + str(heavy) +"|" + str(mech) +"\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This will retrieve data from the Census API and it will append to a csv file.