63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
import requests, json, pprint, discord
|
|
from bs4 import BeautifulSoup
|
|
|
|
def get_player(player):
|
|
# try:
|
|
url = "https://battlefieldtracker.com/bfv/profile/origin/" + player + "/overview"
|
|
headers = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; Win64; x64)' }
|
|
response = requests.get(url, headers=headers).text
|
|
soup = BeautifulSoup(response, "html.parser")
|
|
script = soup.find_all("script")
|
|
|
|
jsonstring = str(script[1])
|
|
jsonstring = jsonstring[33:-131]
|
|
data = json.loads(jsonstring)
|
|
|
|
# Get Player Data
|
|
origin_name = 'bfv|origin|' + player
|
|
|
|
base_stat_blob = data['stats-v2']['standardProfiles'][origin_name]
|
|
account_name = base_stat_blob['platformInfo']['platformUserHandle']
|
|
avatar_url = base_stat_blob['platformInfo']['avatarUrl']
|
|
|
|
stats_overview = base_stat_blob['segments'][0]['stats']
|
|
rank = stats_overview['rank']
|
|
rank_title = rank['metadata']['label']
|
|
rank_number = rank['displayValue']
|
|
|
|
# Build the embed
|
|
embed = discord.Embed(description='-------', color=15105570, type="rich")
|
|
embed.set_thumbnail(url=avatar_url)
|
|
embed.set_author(name="Battlefield V stats for %s" % account_name)
|
|
embed.add_field(name="**Rank**", value="%s, %s" % (rank_number, rank_title), inline=False)
|
|
|
|
gameplay_stats = [
|
|
'scorePerMinute',
|
|
'kdRatio',
|
|
'assists',
|
|
'shotsAccuracy',
|
|
'killStreak',
|
|
'dogtagsTaken',
|
|
'headshots',
|
|
'longestHeadshot',
|
|
'heals',
|
|
'revives',
|
|
'revivesRecieved',
|
|
'resupplies',
|
|
'aceSquad',
|
|
'wlPercentage',
|
|
]
|
|
|
|
for stat in gameplay_stats:
|
|
# print(stat)
|
|
embed.add_field(name="**%s**" % stat.title(), value=stats_overview[stat]['displayValue'], inline=False)
|
|
# embed.add_field(name='Raw value', value=stats_overview[stat]['displayValue'], inline=True)
|
|
# embed.add_field(name='Global Percentile', value=stats_overview[stat]['percentile'], inline=True)
|
|
return embed
|
|
# except Exception:
|
|
# return 'nope'
|
|
|
|
# assault_stats = base_stat_blob['segments'][9]
|
|
# medic_stats = base_stat_blob['segments'][10]
|
|
|
|
# pp.pprint(medic_stats) |