Skip to content

Commit

Permalink
Handle plainlist usage in move fields
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhijeetKrishnan committed Sep 28, 2024
1 parent dd21ddd commit c3da1a5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
22 changes: 22 additions & 0 deletions src/frame_service/wavu/tests/test_wavu.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,25 @@ def test_get_frame_data() -> None:
def test_all_char_meta() -> None:
wavu = Wavu()
assert len(wavu.character_meta) == NUM_CHARACTERS


def test_crush_states_dotlist() -> None:
wavu = Wavu()
with requests.session() as session:
char = wavu.get_frame_data(CharacterName.ZAFINA, session)
assert "&lt" not in char.movelist["Zafina-MNT.uf+3"].notes
assert "div" not in char.movelist["Zafina-MNT.uf+3"].notes


def test_name_dotlist() -> None:
wavu = Wavu()
with requests.session() as session:
char = wavu.get_frame_data(CharacterName.YOSHIMITSU, session)
assert "div" not in char.movelist["Yoshimitsu-b+1+2"].name


def test_startup_dotlist() -> None:
wavu = Wavu()
with requests.session() as session:
char = wavu.get_frame_data(CharacterName.YOSHIMITSU, session)
assert "div" not in char.movelist["Yoshimitsu-KIN.f+1"].startup
32 changes: 22 additions & 10 deletions src/frame_service/wavu/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import requests
from bs4 import BeautifulSoup

from framedb.character import Move
from framedb.character import DiscordMd, Move
from framedb.const import CharacterName

WAVU_API_URL = "https://wavu.wiki/w/api.php"
Expand Down Expand Up @@ -90,6 +90,15 @@ def _process_dotlist(dotlist: str) -> List[str]:
return dotlist.replace("* ", "").split("\n")


def _stringify_dotlist(dotlist: List[str]) -> DiscordMd:
"Join a list of strings into a dotlist string"

if len(dotlist) == 1:
return dotlist[0]
else:
return "* " + "\n* ".join(dotlist)


def _convert_json_move(move_json: Any) -> WavuMove:
"""
Convert a JSON response object into a WavuMove object
Expand All @@ -99,7 +108,7 @@ def _convert_json_move(move_json: Any) -> WavuMove:
id = _normalize_data(move_json["id"])
parent = _normalize_data(move_json["parent"])

name = html.unescape(_process_links(move_json["name"]))
name = _stringify_dotlist(_process_dotlist(_remove_html_tags(html.unescape(_process_links(move_json["name"])))))

input = html.unescape(html.unescape(_normalize_data(move_json["input"])))

Expand All @@ -115,7 +124,7 @@ def _convert_json_move(move_json: Any) -> WavuMove:
if not on_ch or on_ch == "":
on_ch = on_hit

startup = _normalize_data(move_json["startup"])
startup = _stringify_dotlist(_process_dotlist(_normalize_data(move_json["startup"])))

recovery = _normalize_data(move_json["recv"])

Expand Down Expand Up @@ -148,13 +157,16 @@ def _convert_json_move(move_json: Any) -> WavuMove:
video = ""

notes = _remove_html_tags(_process_links(move_json["notes"])).strip()
crush = _normalize_data(move_json["crush"])
if "pc" in crush:
notes += "\n* Power Crush"
if "js" in crush:
notes += "\n"
if "cs" in crush:
notes += "\n" + crush
crush = _process_dotlist(_remove_html_tags(html.unescape(_normalize_data(move_json["crush"]))))
for state in crush:
if "pc" in state:
notes += "\n* Power Crush"
elif "js" in state:
notes += "\n" + state
elif "cs" in state:
notes += "\n" + state
else:
notes += "\n" + state

move = WavuMove(
id,
Expand Down

0 comments on commit c3da1a5

Please sign in to comment.