86 lines
2.2 KiB
Python
Executable File
86 lines
2.2 KiB
Python
Executable File
from bs4 import BeautifulSoup
|
|
import requests
|
|
import random
|
|
|
|
|
|
def request_wiki(url, heading):
|
|
response = requests.get(
|
|
"https://escapefromtarkov.fandom.com/wiki/Category:" + url, timeout=25
|
|
).text
|
|
soup = BeautifulSoup(response, "html.parser")
|
|
h2_heading = soup.find("h2", string=f'Pages in category "{heading}"')
|
|
return [link.text for link in h2_heading.find_next("div").find_all("a")]
|
|
|
|
|
|
def allowed_level_roll():
|
|
message = "None"
|
|
allowed = random.randint(0, 1) == 1
|
|
if allowed:
|
|
message = "Allowed"
|
|
message += ", Trader level: " + random.choice(
|
|
[str(random.randint(1, 4)), "Any level"]
|
|
)
|
|
return message
|
|
|
|
|
|
def query_tarkov_api(query):
|
|
headers = {"Content-Type": "application/json"}
|
|
return requests.post(
|
|
"https://api.tarkov.dev/graphql", headers=headers, json={"query": query}
|
|
).json()["data"]
|
|
|
|
|
|
def tarkov_boss_info():
|
|
"""
|
|
Returns a dict of boss spawn chances per map, and their escorts
|
|
"""
|
|
|
|
query = """{
|
|
maps {
|
|
name
|
|
bosses {
|
|
name
|
|
spawnChance
|
|
escorts {
|
|
boss {
|
|
name
|
|
}
|
|
amount {
|
|
count
|
|
}
|
|
}
|
|
boss {
|
|
name
|
|
imagePortraitLink
|
|
}
|
|
}
|
|
}
|
|
}"""
|
|
|
|
dont_care = [
|
|
"assault",
|
|
"Infected",
|
|
"BEAR",
|
|
"USEC",
|
|
"Rogue",
|
|
]
|
|
headers = {"Content-Type": "application/json"}
|
|
response = query_tarkov_api(query)["maps"]
|
|
|
|
# Wasteful, but make a new dict to hold the info we care about
|
|
levels = {}
|
|
for level in response:
|
|
levels[level["name"]] = {
|
|
boss["boss"]["name"]: {
|
|
"escorts": sum(
|
|
escort["amount"][0]["count"] for escort in boss["escorts"]
|
|
),
|
|
"spawnChance": f"**{str(round(boss['spawnChance'],2))}%**",
|
|
"picture": boss["boss"]["imagePortraitLink"],
|
|
}
|
|
for boss in level["bosses"]
|
|
if boss["boss"]["name"] not in dont_care
|
|
}
|
|
|
|
return levels
|