Skip to content

Commit

Permalink
changed: a lot
Browse files Browse the repository at this point in the history
  • Loading branch information
chatterchats committed Nov 15, 2024
1 parent a853691 commit 7ef1caa
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 369 deletions.
9 changes: 8 additions & 1 deletion src/cfg/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"User-Agent": "Diveharder API - api.diverharder.com",
"Authorization": os.environ["SESSION_TOKEN"],
},
"time_delay": 20,
"time_delay": int(20),
}


Expand All @@ -38,6 +38,7 @@
"war_id": war_id_url,
"planet_stats": base_url + os.environ["PLANET_STATS"],
"major_order": base_url + os.environ["MAJOR_ORDER"],
"personal_order": base_url + os.environ["PERSONAL_ORDER"],
"news_feed": base_url + os.environ["NEWS_FEED"],
"updates": os.environ["STEAM_NEWS"],
"level_spec": base_url + os.environ["LEVEL_SPEC"],
Expand All @@ -49,6 +50,12 @@
"season_pass_sv": base_url + os.environ["SEASON_PASS_SV"],
"season_pass_ce": base_url + os.environ["SEASON_PASS_CE"],
"season_pass_dd": base_url + os.environ["SEASON_PASS_DD"],
"season_pass_pp": base_url + os.environ["SEASON_PASS_PP"],
"season_pass_vc": base_url + os.environ["SEASON_PASS_VC"],
"season_pass_ff": base_url + os.environ["SEASON_PASS_FF"],
"season_pass_ca": base_url + os.environ["SEASON_PASS_CA"],
"season_pass_te": base_url + os.environ["SEASON_PASS_TE"],
"space_station_1": base_url + os.environ["SPACE_STATION_1"],
"score_calc": base_url + os.environ["MISSION_SCORE_CALC_PARAMS"],
"election_candidates": base_url + os.environ["ELECTION_CANDIDATES"],
"election_terms": base_url + os.environ["ELECTION_TERMS"],
Expand Down
25 changes: 18 additions & 7 deletions src/data/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ def __init__(self):
self.urls = cfg.urls

self.update_time = 0
self.time_delay = cfg.ahgs_api.get("time_delay")
self.time_delay: int = cfg.ahgs_api.get("time_delay", 20)

self.raw_data = {
"status": {"data": [], "update_time": 0, "auth": True},
"war_info": {"data": [], "update_time": 0, "auth": True},
"planet_stats": {"data": [], "update_time": 0, "auth": True},
"major_order": {"data": [], "update_time": 0, "auth": True},
"personal_order": {"data": [], "update_time": 0, "auth": True},
"news_feed": {"data": [], "update_time": 0, "auth": True},
"updates": {"data": [], "update_time": 0, "auth": False},
"level_spec": {"data": [], "update_time": 0, "auth": True},
Expand All @@ -39,6 +40,12 @@ def __init__(self):
"season_pass_sv": {"data": [], "update_time": 0, "auth": True},
"season_pass_ce": {"data": [], "update_time": 0, "auth": True},
"season_pass_dd": {"data": [], "update_time": 0, "auth": True},
"season_pass_pp": {"data": [], "update_time": 0, "auth": True},
"season_pass_vc": {"data": [], "update_time": 0, "auth": True},
"season_pass_ff": {"data": [], "update_time": 0, "auth": True},
"season_pass_ca": {"data": [], "update_time": 0, "auth": True},
"season_pass_te": {"data": [], "update_time": 0, "auth": True},
"space_station_1": {"data": [], "update_time": 0, "auth": False},
"score_calc": {"data": [], "update_time": 0, "auth": True},
"election_candidates": {"data": [], "update_time": 0, "auth": True},
"election_terms": {"data": [], "update_time": 0, "auth": True},
Expand Down Expand Up @@ -66,9 +73,12 @@ async def update_all(self):
self.raw_data[key]["data"] = responses[i]
self.raw_data[key]["update_time"] = int(time())
if key == "updates":
self.raw_data[key]["data"] = await self.format_steam_news(
self.raw_data[key]["data"]["appnews"]["newsitems"]
)
if not isinstance(self.raw_data[key]["data"], list):
# If pulling from steam, we gotta format, otherwise you're probably using my shit, so it's already formatted
# and we just leave it alone
self.raw_data[key]["data"] = await self.format_steam_news(
self.raw_data[key]["data"]["appnews"]["newsitems"]
)
self.update_time = int(time())

async def fetch_all(self):
Expand All @@ -94,7 +104,7 @@ async def fetch_data(self, info_name: str = ""):
)
)
if update_needed:
authed = self.raw_data.get(info_name)["auth"]
authed = self.raw_data.get(info_name, {})["auth"]
url = self.urls[info_name]
self.raw_data[info_name]["update_time"] = int(time())
self.raw_data[info_name]["data"] = await self.get_url(url, authed)
Expand Down Expand Up @@ -164,7 +174,8 @@ async def format_steam_news(self, all_news):
news["contents"] = sub(r"\[b](.+?)\[/b]", r"\n**\1**", news["contents"])
news["contents"] = sub(r"\[i](.+?)\[/i]", r"*\1*", news["contents"])
news["contents"] = sub(r"\[u](.+?)\[/u]", r"\n__\1__", news["contents"])
news["contents"] = sub(r"\[list](.+?)\[/list]", r"\1", news["contents"])
news["contents"] = sub(r"\[\*]", r" - ", news["contents"])
news["contents"] = sub(r"\[list]", r"", news["contents"])
news["contents"] = sub(r"\[/list]", r"", news["contents"])
news["contents"] = sub(r"\[\*]", r"- ", news["contents"])
news["contents"] = news["contents"].replace("\n\n", "\n")
return all_news
11 changes: 8 additions & 3 deletions src/data/json_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def get_jsons_from_github():
if not os.path.exists(path):
log.msg("Clone JSON Repository")
git.Repo.clone_from(git_url, path)
else:
"""else:
log.msg("Pull JSON Repository")
repo = git.Repo(path)
repo.remotes.origin.pull()
repo.remotes.origin.pull()"""


def get_json_files():
Expand Down Expand Up @@ -70,6 +70,11 @@ def sort_json_dicts():
"steeled_veterans": raw_json_data["warbonds_steeled_veterans"],
"cutting_edge": raw_json_data["warbonds_cutting_edge"],
"democratic_detonation": raw_json_data["warbonds_democratic_detonation"],
"polar_patriots": raw_json_data["warbonds_polar_patriots"],
"viper_commandos": raw_json_data["warbonds_viper_commandos"],
"freedoms_flame": raw_json_data["warbonds_freedoms_flame"],
"chemical_agents": raw_json_data["warbonds_chemical_agents"],
"truth_enforcers": raw_json_data["warbonds_truth_enforcers"],
},
"factions": raw_json_data["factions"],
}
Expand Down Expand Up @@ -160,7 +165,7 @@ def expand_json():
page["assets"][item_id].update(
json_data["items"]["weapons"]["grenades"][item_id]
)
page["assets"][item_id].update({"medal_cost": item["medal_cost"]})
page["assets"][item_id].update({"medal_cost": item.get("medal_cost", 0)})
page["items"] = page["assets"]
page.pop("assets")

Expand Down
Loading

0 comments on commit 7ef1caa

Please sign in to comment.