-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added gamemodes in local CSV file instead of calling Blizzard
- Loading branch information
Showing
46 changed files
with
258 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
key,name,description | ||
assault,Assault,"Teams fight to capture or defend two successive points against the enemy team. It's an inactive Overwatch 1 gamemode, also called 2CP." | ||
capture-the-flag,Capture the Flag,Teams compete to capture the enemy team’s flag while defending their own. | ||
control,Control,Teams fight to hold a single objective. The first team to win two rounds wins the map. | ||
deathmatch,Deathmatch,Race to reach 20 points first by racking up kills in a free-for-all format. | ||
elimination,Elimination,"Dispatch all enemies to win the round. Win three rounds to claim victory. Available with teams of one, three, or six." | ||
escort,Escort,"One team escorts a payload to its delivery point, while the other races to stop them." | ||
flashpoint,Flashpoint,"Teams fight for control of key positions across the map, aiming to capture three of them before their opponents do." | ||
hybrid,Hybrid,"Attackers capture a payload, then escort it to its destination; defenders try to hold them back." | ||
push,Push,Teams battle to take control of a robot and push it toward the enemy base. | ||
team-deathmatch,Team Deathmatch,Team up and triumph over your enemies by scoring the most kills. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,27 @@ | ||
"""Gamemodes Parser module""" | ||
from app.config import settings | ||
|
||
from .api_parser import APIParser | ||
from .generics.csv_parser import CSVParser | ||
|
||
|
||
class GamemodesParser(APIParser): | ||
class GamemodesParser(CSVParser): | ||
"""Overwatch map gamemodes list page Parser class""" | ||
|
||
root_path = settings.home_path | ||
timeout = settings.home_path_cache_timeout | ||
filename = "gamemodes" | ||
|
||
def parse_data(self) -> list[dict]: | ||
gamemodes_container = ( | ||
self.root_tag.find("div", class_="maps", recursive=False) | ||
.find("blz-carousel-section", recursive=False) | ||
.find("blz-carousel", recursive=False) | ||
) | ||
|
||
gamemodes_extras = [ | ||
{ | ||
"key": feature_div["label"], | ||
"description": ( | ||
feature_div.find("blz-header") | ||
.find("div", slot="description") | ||
.get_text() | ||
.strip() | ||
), | ||
"screenshot": feature_div.find("blz-image")["src:min-plus"], | ||
} | ||
for feature_div in gamemodes_container.find_all("blz-feature") | ||
] | ||
|
||
return [ | ||
{ | ||
"key": gamemodes_extras[gamemode_index]["key"], | ||
"name": gamemode_div.get_text(), | ||
"icon": gamemode_div.find("blz-image")["src:min-plus"], | ||
"description": gamemodes_extras[gamemode_index]["description"], | ||
"screenshot": gamemodes_extras[gamemode_index]["screenshot"], | ||
} | ||
for gamemode_index, gamemode_div in enumerate( | ||
gamemodes_container.find("blz-tab-controls").find_all( | ||
"blz-tab-control", | ||
"key": gamemode["key"], | ||
"name": gamemode["name"], | ||
"icon": self.get_static_url( | ||
f"{gamemode['key']}-icon", | ||
extension="svg", | ||
), | ||
) | ||
"description": gamemode["description"], | ||
"screenshot": self.get_static_url( | ||
gamemode["key"], | ||
extension="avif", | ||
), | ||
} | ||
for gamemode in self.csv_data | ||
] |
Empty file.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Abstract API Parser module""" | ||
from abc import abstractmethod | ||
|
||
from app.common.helpers import read_csv_data_file | ||
from app.config import settings | ||
|
||
from .abstract_parser import AbstractParser | ||
|
||
|
||
class CSVParser(AbstractParser): | ||
"""CSV Parser class used to define generic behavior for parsers used | ||
to extract data from local CSV files. | ||
""" | ||
|
||
# Timeout to use for every CSV-based data | ||
timeout = settings.csv_cache_timeout | ||
|
||
# Name of CSV file to retrieve (without extension), also | ||
# used as a sub-folder name for storing related static files | ||
filename: str | ||
|
||
async def retrieve_and_parse_data(self) -> None: | ||
"""Method used to retrieve data from CSV file and storing | ||
it into self.data attribute | ||
""" | ||
|
||
# Read the CSV file | ||
self.csv_data = read_csv_data_file(f"{self.filename}.csv") | ||
|
||
# Parse the data | ||
self.data = self.parse_data() | ||
|
||
# Update the Parser Cache | ||
self.cache_manager.update_parser_cache(self.cache_key, self.data, self.timeout) | ||
|
||
@abstractmethod | ||
def parse_data(self) -> dict | list[dict]: | ||
"""Main submethod of the parser, mainly doing the parsing of CSV data and | ||
returning a dict, which will be cached and used by the API. Can | ||
raise an error if there is an issue when parsing the data. | ||
""" | ||
|
||
def get_static_url(self, key: str, extension: str = "jpg") -> str: | ||
"""Method used to retrieve the URL of a local static file""" | ||
return f"{settings.app_base_url}/static/{self.filename}/{key}.{extension}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "overfast-api" | ||
version = "2.19.3" | ||
version = "2.19.4" | ||
description = "Overwatch API giving data about heroes, maps, and players statistics." | ||
license = "MIT" | ||
authors = ["TeKrop <[email protected]>"] | ||
|
@@ -12,14 +12,14 @@ documentation = "https://overfast-api.tekrop.fr/" | |
[tool.poetry.dependencies] | ||
python = "^3.11" | ||
beautifulsoup4 = "^4.12.2" | ||
fastapi = "^0.101.0" | ||
fastapi = "^0.103.0" | ||
httpx = {extras = ["http2"], version = "^0.24.1"} | ||
loguru = "^0.7.0" | ||
lxml = "^4.9.3" | ||
redis = "^4.6.0" | ||
redis = "^5.0.0" | ||
uvicorn = {extras = ["standard"], version = "^0.23.2"} | ||
pydantic = "^2.1.1" | ||
pydantic-settings = "^2.0.2" | ||
pydantic = "^2.3.0" | ||
pydantic-settings = "^2.0.3" | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
black = "^23.7.0" | ||
|
Oops, something went wrong.