fstrings and some lru caching
All checks were successful
Build and push / changes (push) Successful in 4s
Build and push / Lint-Python (push) Successful in 2s
Build and push / Build-and-Push-Docker (push) Successful in 13s
Build and push / sync-argocd-app (push) Successful in 2s
Build and push / post-failure-to-discord (push) Has been skipped
Build and push / post-success-to-discord (push) Successful in 1s
All checks were successful
Build and push / changes (push) Successful in 4s
Build and push / Lint-Python (push) Successful in 2s
Build and push / Build-and-Push-Docker (push) Successful in 13s
Build and push / sync-argocd-app (push) Successful in 2s
Build and push / post-failure-to-discord (push) Has been skipped
Build and push / post-success-to-discord (push) Successful in 1s
This commit is contained in:
parent
e6c6bd5627
commit
f4d0c1cb03
@ -4,6 +4,7 @@ from discord.ext import commands
|
||||
import discord
|
||||
import os
|
||||
import requests
|
||||
from functools import lru_cache
|
||||
|
||||
import core_utils
|
||||
import star_citizen
|
||||
@ -70,9 +71,12 @@ class StarCitizen(commands.Cog):
|
||||
await ctx.defer()
|
||||
await ctx.send_followup(embed=embed)
|
||||
|
||||
@staticmethod
|
||||
@lru_cache(maxsize=300)
|
||||
async def get_all_ships(ctx: discord.AutocompleteContext):
|
||||
"""
|
||||
returns a list of all ships in the game, which can then be passed to the /ship command for auto complete
|
||||
Returns a list of all ships in the game, which can then be passed to the /ship command for auto complete.
|
||||
Cached to reduce repeated web requests.
|
||||
"""
|
||||
url = "https://starcitizen.tools/Category:Ships"
|
||||
response = requests.get(url, timeout=25).text
|
||||
@ -98,9 +102,11 @@ class StarCitizen(commands.Cog):
|
||||
embed = await star_citizen.get_ship(ship_name=ship)
|
||||
await ctx.send_followup(embed=embed)
|
||||
|
||||
@staticmethod
|
||||
@lru_cache(maxsize=1)
|
||||
async def get_all_commodities(ctx: discord.AutocompleteContext):
|
||||
"""
|
||||
Returns a list of commododites that can be used for autocomplete
|
||||
Returns a list of commodities that can be used for autocomplete
|
||||
for the /trade function.
|
||||
Turning off its call to the API just to save key usage / i hear the devs
|
||||
took data out of the game files so this may go away soon
|
||||
@ -228,7 +234,7 @@ class StarCitizen(commands.Cog):
|
||||
)
|
||||
@option(
|
||||
name="scu",
|
||||
description="Optinal how much SCU to fill",
|
||||
description="Optional how much SCU to fill",
|
||||
required=False,
|
||||
min_value=1,
|
||||
max_value=98304,
|
||||
|
@ -5,6 +5,7 @@ import discord
|
||||
import os
|
||||
import json
|
||||
import requests
|
||||
from functools import lru_cache
|
||||
|
||||
import tarkov
|
||||
|
||||
@ -63,6 +64,7 @@ class Tarkov(commands.Cog):
|
||||
with open(local_spawn_rates, "w") as f:
|
||||
json.dump(spawns_from_api, f)
|
||||
|
||||
@lru_cache(maxsize=32)
|
||||
async def get_all_bosses(ctx: discord.AutocompleteContext):
|
||||
"""
|
||||
Returns a list of boss names to be used in auto complete
|
||||
@ -242,7 +244,7 @@ class Tarkov(commands.Cog):
|
||||
|
||||
wiki_url = "https://escapefromtarkov.fandom.com/wiki/"
|
||||
|
||||
response = requests.get(wiki_url + boss_name).text
|
||||
response = requests.get(f"{wiki_url}{boss_name}").text
|
||||
soup = BeautifulSoup(response, "html.parser")
|
||||
|
||||
# boss_info = tarkov.get_tarkov_boss_info()
|
||||
@ -286,7 +288,7 @@ class Tarkov(commands.Cog):
|
||||
embed.add_field(name="Spawn Chance", value=f"**{spawn_chance}**", inline=False)
|
||||
|
||||
embed.add_field(
|
||||
name="Link", value=f"{wiki_url + boss_name.replace(' ', '_')}", inline=False
|
||||
name="Link", value=f"{wiki_url}{boss_name.replace(' ', '_')}", inline=False
|
||||
)
|
||||
await ctx.send_followup(embed=embed)
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
def request_wiki(url, heading):
|
||||
response = requests.get(
|
||||
"https://escapefromtarkov.fandom.com/wiki/Category:" + url, timeout=25
|
||||
f"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}"')
|
||||
@ -18,7 +19,11 @@ def query_tarkov_api(query):
|
||||
).json()["data"]
|
||||
|
||||
|
||||
@lru_cache(maxsize=32)
|
||||
def get_boss_pictures():
|
||||
"""
|
||||
Cached function to get boss pictures
|
||||
"""
|
||||
return query_tarkov_api(
|
||||
"""{
|
||||
bosses(lang: en, gameMode:pve) {
|
||||
@ -89,6 +94,9 @@ def get_tarkov_boss_info():
|
||||
|
||||
|
||||
def compare_boss_spawns(known_spawns: dict, spawns_from_api: dict) -> dict:
|
||||
"""
|
||||
Not cached as this function compares changing data
|
||||
"""
|
||||
changes = {} # To store the changes
|
||||
|
||||
for level in known_spawns:
|
||||
|
Loading…
x
Reference in New Issue
Block a user