Skip to content

Commit

Permalink
Various fixes and improvements (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
WitherredAway authored Sep 15, 2023
1 parent 2856613 commit b15e9e2
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 195 deletions.
39 changes: 14 additions & 25 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
import csv
import re
from collections import defaultdict
from pathlib import Path
from urllib.parse import urljoin

from . import models

DESCRIPTION_LINK_REGEX = re.compile(r"\[(.+?)\]\{.+?\}")


def isnumber(v):
try:
int(v)
except ValueError:
return False
return True

from .constants import ARTISTS, DESCRIPTION_LINK_REGEX
from .utils import comma_formatted, get_data_from, isnumber

def get_data_from(filename):
path = Path(__file__).parent / "csv" / filename

with open(path) as f:
reader = csv.DictReader(f)
data = list({k: int(v) if isnumber(v) else v for k, v in row.items() if v != ""} for row in reader)

return data
from . import models


def get_pokemon(instance):
Expand Down Expand Up @@ -122,6 +102,15 @@ def get_evolution_trigger(pid):
if "name.fr" in row:
names.append(("🇫🇷", row["name.fr"]))

art_credit = row.get("credit")
if art_credit:
# Each user in the credit must be separated by `|`.
# And gotta make sure that no username ever contains a `|`,
# but ideally they should all be user ID anyway
artist_ids = [int(s) if isnumber(s) else s.strip() for s in str(art_credit).split("|")]
artists = [ARTISTS.get(aid, aid) for aid in artist_ids]
art_credit = comma_formatted(artists)

pokemon[row["id"]] = models.Species(
id=row["id"],
names=names,
Expand Down Expand Up @@ -154,7 +143,7 @@ def get_evolution_trigger(pid):
is_form="is_form" in row,
form_item=row["form_item"] if "form_item" in row else None,
region=row["region"],
art_credit=row.get("credit"),
art_credit=art_credit,
instance=instance,
)

Expand Down Expand Up @@ -213,7 +202,7 @@ def get_effects(instance):
effects = {}

for row in data:
description = re.sub(DESCRIPTION_LINK_REGEX, r"\1", row["short_effect"])
description = DESCRIPTION_LINK_REGEX.sub(r"\1", row["short_effect"])
description = description.replace("$effect_chance", "{effect_chance}")
effects[row["move_effect_id"]] = models.MoveEffect(
id=row["move_effect_id"], description=description, instance=instance
Expand Down
32 changes: 32 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import re


DESCRIPTION_LINK_REGEX = re.compile(r"\[.*?\]\{.*?:(.*?)\}")


STAT_STAGE_MULTIPLIERS = {
-6: 2 / 8,
-5: 2 / 7,
Expand Down Expand Up @@ -121,3 +127,29 @@
[None, 1, 0.5, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 0.5, 0.5],
[None, 1, 2, 1, 0.5, 1, 1, 1, 1, 0.5, 0.5, 1, 1, 1, 1, 1, 2, 2, 1],
]


ARTISTS = {
405452200656109569: "HiroWilde#6159",
304098467192635392: "@superjedi224",
130438329484181504: "@haltfire302",
285861483412193280: "@anoea",
326895657803710477: "@chaotichavoc",
494656111627075594: "@dotkura",
711892049842012190: "@somebluepigeon",
444692790689923072: "@5h3s",
550289905079812106: "@rengokukyojuro8008",
810031895190306816: "@ironlegend09",
611659645760831506: "@dagger_mace",
850079219681722398: "@foxrii_",
712521240602214400: "@blubambii",
979108831118364774: "@yushiyoto",
745825974880436294: "@jasreetdhillon",
690194873650905155: "@notchri",
676169170400051201: "Misfortune#8519",
559768825361596442: "@.typenull.",
484526479770910728: "@stranger1200",
859645802899963923: "@a_dood_1336",
336148113465278464: "@bren.__.",
243763234685976577: "@metspek"
}
6 changes: 4 additions & 2 deletions csv/evolution.csv
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ id,evolved_species_id,evolution_trigger_id,trigger_item_id,minimum_level,gender_
433,858,1,,42,,,,,,,,,,,,,,0,0
434,860,1,,32,,,,,,,,,,,,,,0,0
435,861,1,,42,,,,,,,,,,,,,,0,0
436,862,1,,35,,,,,,,,,,,,,,0,0
436,862,1,,35,,,,night,,,,,,,,,,0,0
437,863,1,,28,,,,,,,,,,,,,,0,0
438,864,1,,38,,,,,,,,,,,,,,0,0
439,865,5,,,,,,,,,,,,,,,,0,0
Expand Down Expand Up @@ -492,4 +492,6 @@ id,evolved_species_id,evolution_trigger_id,trigger_item_id,minimum_level,gender_
,10222,3,82,,,,,,,,,,,,,,,0,0
,10224,3,85,,,,,,,,,,,,,,,0,0
,10231,1,,30,,,,,,,,,,,,,,0,0
,10234,1,,50,,,,night,,,,,,,,,,0,0
,10234,1,,50,,,,,,,,,,,,,,0,0
,10160,1,,40,,,,,,,,,,,,,,,
,10172,1,,20,,,,,,,,,,,,,,,
Loading

0 comments on commit b15e9e2

Please sign in to comment.