61 lines
1.8 KiB
Python
Executable File
61 lines
1.8 KiB
Python
Executable File
import requests, json, pprint, discord
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
def get_player(player):
|
|
player = player.lower()
|
|
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:
|
|
embed.add_field(
|
|
name="**%s**" % stats_overview[stat]["displayName"],
|
|
value=stats_overview[stat]["displayValue"],
|
|
inline=True,
|
|
)
|
|
return embed
|