dragon-bot/app/tarkov.py
Luke R 1897f63bd0
Some checks failed
Build and push / sync-argocd-app (push) Blocked by required conditions
Build and push / changes (push) Successful in 5s
Build and push / Lint-Python (push) Successful in 8s
Build and push / Build-and-Push-Docker (push) Has been cancelled
im so dumb. fix the docker file
2024-11-10 15:54:55 -08:00

119 lines
3.6 KiB
Python
Executable File

from bs4 import BeautifulSoup
import requests
import random
import json
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 get_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",
]
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'] * 100, 2))}%**",
"picture": boss["boss"]["imagePortraitLink"],
}
for boss in level["bosses"]
if boss["boss"]["name"] not in dont_care
}
return levels
def compare_boss_spawns(known_spawns: dict, spawns_from_api: dict) -> dict:
changes = {} # To store the changes
# diff = DeepDiff(known_spawns, spawns_from_api, ignore_order=True, verbose_level=2)
# # Get the differences between the two JSON blobs
# # Iterate through the diff to find spawnChance differences
# for key, changes in diff.items():
# if key == 'values_changed':
# for path, change in changes.items():
# # Access the level and boss name directly from the path
# level, boss = path.split('[')[1].split(']')[0], path.split('[')[2].split(']')[0]
# # Print the relevant difference in spawnChance
# if 'new_value' in change:
# print(f"Level: {level}, Boss: {boss}, Diff in spawnChance: {change['old_value']} -> {change['new_value']}")
for level in known_spawns:
level_changes = {} # Store changes for each level
for boss in known_spawns.get(level, {}):
known_boss_info = known_spawns[level].get(boss, {})
api_boss_info = spawns_from_api[level].get(boss, {})
old = known_boss_info.get("spawnChance", "**0%**")
new = api_boss_info.get("spawnChance", "**0%**")
if new != old:
level_changes[boss] = f"{old} -> {new}"
changes[level] = level_changes
return changes