JavaScript is required to use Bungie.net

Forums

originally posted in:BungieNetPlatform
Edited by Prometheus25: 10/19/2015 2:46:27 AM
1

Sharing my first API project

[spoiler]import requests import json from pprint import pprint import pandas as pd #Universal Static Data HEADERS = {"X-API-Key":'[REDACTED]'} url = "http://www.bungie.net/Platform/Destiny/Stats/" stype = "?periodType=Daily" pve = "&modes=AllPvE" pvp = "&modes=AllPvP" start = "&daystart=2015-10-12" end = "&dayend=2015-10-12" #Initialize some values PvP_total = 0.0 PvE_total = 0.0 #Lets read in the data with open("Statistics.txt", "w") as statistics: with open("25OCT2015_Charity_Brawl_Participant_List.txt", "r") as players: for line in players: currentline = line.strip().split(",") Bnet_name = currentline[0] + " " GamerID = "(" + currentline[1] +") " pid = currentline[2] #PvE Data Grab params = stype + pve + start + end response = requests.get(str(url+pid+params), headers=HEADERS) activity = response.json() #Diagnostic Prints #print(json.dumps(activity['Response']['allPvE']['daily'][0]['values']['kills']['basic']['value'], sort_keys=True, indent=3)) eKills = 0 if('daily' in activity['Response']['allPvE']): eKills_s = json.dumps(activity['Response']['allPvE']['daily'][0]['values']['kills']['basic']['value']) eKills = int(float(eKills_s)) #PvP Data Grab params = stype + pvp + start + end response = requests.get(url+pid+params, headers=HEADERS) activity = response.json() #Diagnostic Prints #print(json.dumps(activity['Response']['allPvP'], sort_keys=True, indent=3)) pKills = 0 if('daily' in activity['Response']['allPvP']): pKills_s = json.dumps(activity['Response']['allPvP']['daily'][0]['values']['kills']['basic']['value']) pKills = float(pKills_s) #Update running totals PvP_total = PvP_total + pKills PvE_total = PvE_total + eKills outstring = 'PvE kills: ' + str(eKills) + ' Earned: ' + str(eKills*0.01) outstring = outstring + ' PvP kills: ' + str(pKills) +' Earned: ' + str(pKills*0.03) outstring = outstring + ' Total Earned: ' + str(eKills*0.01 + pKills*0.03) + "\n" #Totals Print outstring_final = Bnet_name + GamerID + outstring print(outstring_final) statistics.write(outstring_final) total = PvP_total*0.03 + PvE_total*0.01 total_string = "\nTotal PvE kills: " + str(PvE_total) total_string = total_string + " Total PvP kills: " + str(PvP_total) total_string2 = "\nTotal earned toward charity: " + str(PvE_total) + "*0.01 + " total_string2 = total_string2 + str(PvP_total) + "*0.03 = " + str(total) statistics.write(total_string) statistics.write(total_string2)[/spoiler] Just wanted to share my first BungieNetPlatform project, a script I wrote to pull the number of kills in PvP and PvE for a comma-separated list of players participating in a Charity event I'm hosting in a group here. Grabs kills, totals the monetary value I've associated with them (0.01 for a PvE kill and 0.03 for a PvP kill), and saves the data to a text file for saving. Hoping to take this framework and scale it to a larger project I have in mind. Edit: Are there any better ways to share code, perhaps via offsite?
English

Posting in language:

 

Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

  • [quote]Edit: Are there any better ways to share code, perhaps via offsite?[/quote]A project on GitHub would be the best solution, but if you just need a place to quickly dump some code, [url=https://gist.github.com/]Gist[/url] or [url=http://pastebin.com/]pastebin[/url] will work.

    Posting in language:

     

    Play nice. Take a minute to review our Code of Conduct before submitting your post. Cancel Edit Create Fireteam Post

You are not allowed to view this content.
;
preload icon
preload icon
preload icon