67 lines
2.2 KiB
Python
67 lines
2.2 KiB
Python
from datetime import date
|
|
import json
|
|
import pprint
|
|
import requests
|
|
|
|
account_name = 'Truttle%231248'
|
|
base_url = 'https://www.bungie.net/Platform/Destiny2'
|
|
headers = {'X-API-KEY': '777984975407420ba392ad951e37e406'}
|
|
pp = pprint.PrettyPrinter(indent=4)
|
|
|
|
def parse_message(message):
|
|
"""
|
|
parse_message(message)
|
|
|
|
Handles the message and looks for the player's name.
|
|
"""
|
|
# Return the player's name
|
|
name = message.content.split()[1]
|
|
if len(message.content.split()) > 1:
|
|
name = message.content.split()[1:].repalce('#', '%23')
|
|
|
|
return get_account_blob(player=name)
|
|
|
|
|
|
def get_account_blob(account_name):
|
|
initial_blob = requests.get(
|
|
"%s/SearchDestinyPlayer/-1/%s" % (base_url, account_name),
|
|
headers=headers
|
|
).json()
|
|
|
|
character_map = {}
|
|
account_metadata = initial_blob['Response'][0]
|
|
print(account_metadata)
|
|
|
|
# character_map['profile_id'] = account_metadata['membershipId']
|
|
# character_map['account_type'] = account_metadata['membershipType']
|
|
|
|
# account_url = "%s/%s/Profile/%s/?components=100" % (base_url, character_map['account_type'], character_map['profile_id'])
|
|
# account_blob = requests.get(account_url, headers=headers).json()['Response']['profile']['data']
|
|
|
|
# character_map['player_name'] = account_blob['userInfo']['displayName']
|
|
# character_map['date_last_played'] = account_blob['dateLastPlayed']
|
|
# character_map['character_ids'] = [int(x) for x in account_blob['characterIds']]
|
|
# return character_map
|
|
|
|
|
|
def get_character_info(account_type, profile_id, character_id):
|
|
character_url = "%s/%s/Profile/%s/Character/%s/?components=200" % (base_url, account_type, profile_id, character_id)
|
|
|
|
return requests.get(character_url, headers=headers).json()['Response']['character']['data']
|
|
|
|
|
|
def get_clan_info(account_type, profile_id):
|
|
group_url = "https://www.bungie.net/Platform/GroupV2/User/%s/%s/0/1/" % (account_type, str(profile_id))
|
|
print(group_url)
|
|
|
|
return requests.get(group_url, headers=headers).json()
|
|
|
|
if __name__ == '__main__':
|
|
print get_account_blob(account_name)
|
|
|
|
# account_type = get_account_blob(account_name)['account_type'],
|
|
# profile_id = get_account_blob(account_name)['profile_id'],
|
|
|
|
# pp.pprint(
|
|
# get_clan_info(account_type, profile_id)
|
|
# ) |