|
8 | 8 | import sqlite3 |
9 | 9 | from collections import defaultdict |
10 | 10 | import platform |
11 | | -from typing import Any, TYPE_CHECKING, TypeVar |
| 11 | +from typing import TYPE_CHECKING, TypeVar |
12 | 12 |
|
13 | 13 | import click |
14 | 14 | import requests |
@@ -432,82 +432,6 @@ def fetch_images(conn: sqlite3.Connection) -> None: |
432 | 432 | save_maps(conn) |
433 | 433 |
|
434 | 434 |
|
435 | | -def parse_spell_data(lua_content: str) -> list[tuple[str, str, bool, bool, bool, bool, bool]]: |
436 | | - data = lua.execute(lua_content) |
437 | | - offers = [] |
438 | | - for name, table in list(data.items()): |
439 | | - spell_title = name |
440 | | - spell_vocations = list(table["vocation"].values()) |
441 | | - for npc, vocation in table["sellers"].items(): |
442 | | - if isinstance(vocation, bool): |
443 | | - npc_vocations = spell_vocations[:] |
444 | | - elif isinstance(vocation, str): |
445 | | - npc_vocations = [vocation] |
446 | | - else: |
447 | | - npc_vocations = list(vocation.values()) |
448 | | - offers.append(( |
449 | | - npc, |
450 | | - spell_title, |
451 | | - "Knight" in npc_vocations, |
452 | | - "Paladin" in npc_vocations, |
453 | | - "Druid" in npc_vocations, |
454 | | - "Sorcerer" in npc_vocations, |
455 | | - "Monk" in npc_vocations, |
456 | | - )) |
457 | | - return offers |
458 | | - |
459 | | - |
460 | | -def generate_spell_offers(conn: sqlite3.Connection, data_store: dict[str, Any]) -> None: |
461 | | - """Fetch and save the spell offers from the spell data module. |
462 | | -
|
463 | | - Args: |
464 | | - conn: A connection to the database. |
465 | | - data_store: The data store containing information about generated articles. |
466 | | -
|
467 | | - """ |
468 | | - if "npcs_map" not in data_store or "spells_map" not in data_store: |
469 | | - return |
470 | | - article = wiki_client.get_article("Module:ItemPrices/spelldata") |
471 | | - spell_offers = parse_spell_data(article.content) |
472 | | - rows = [] |
473 | | - not_found_store = defaultdict(set) |
474 | | - with ( |
475 | | - timed() as t, |
476 | | - progress_bar(spell_offers, len(spell_offers), "Processing spell offers") as bar, |
477 | | - ): |
478 | | - for npc, spell, knight, paladin, druid, sorcerer, monk in bar: |
479 | | - spell_id = data_store["spells_map"].get(spell.lower()) |
480 | | - if spell_id is None: |
481 | | - not_found_store["spell"].add(spell) |
482 | | - continue |
483 | | - npc_id = data_store["npcs_map"].get(npc.lower()) |
484 | | - if npc_id is None: |
485 | | - not_found_store["npc"].add(npc) |
486 | | - continue |
487 | | - rows.append(( |
488 | | - npc_id, |
489 | | - spell_id, |
490 | | - knight, |
491 | | - sorcerer, |
492 | | - paladin, |
493 | | - druid, |
494 | | - monk, |
495 | | - )) |
496 | | - with conn: |
497 | | - conn.execute("DELETE FROM npc_spell") |
498 | | - conn.executemany( |
499 | | - "INSERT INTO npc_spell(npc_id, spell_id, knight, sorcerer, paladin, druid, monk) VALUES(?, ?, ?, ?, ?, ?, ?)", |
500 | | - rows) |
501 | | - if not_found_store["spell"]: |
502 | | - unknonw_spells = not_found_store["spell"] |
503 | | - click.echo(f"{Fore.RED}Could not parse offers for {len(unknonw_spells):,} spell.{Style.RESET_ALL}") |
504 | | - click.echo(f"\t-> {Fore.RED}{f'{Style.RESET_ALL},{Fore.RED}'.join(unknonw_spells)}{Style.RESET_ALL}") |
505 | | - if not_found_store["npc"]: |
506 | | - unknown_npcs = not_found_store["npc"] |
507 | | - click.echo(f"{Fore.RED}Could not parse offers of {len(unknown_npcs):,} npcs.{Style.RESET_ALL}") |
508 | | - click.echo(f"\t-> {Fore.RED}{f'{Style.RESET_ALL},{Fore.RED}'.join(unknown_npcs)}{Style.RESET_ALL}") |
509 | | - |
510 | | - |
511 | 435 | def generate_item_offers(conn: sqlite3.Connection, data_store): |
512 | 436 | if "npcs_map" not in data_store or "items_map" not in data_store: |
513 | 437 | return |
@@ -670,7 +594,6 @@ def generate(conn, skip_images, skip_deprecated): |
670 | 594 | RashidPositionTable.insert(conn, **position.model_dump()) |
671 | 595 |
|
672 | 596 | generate_item_offers(conn, data_store) |
673 | | - generate_spell_offers(conn, data_store) |
674 | 597 | generate_loot_statistics(conn, data_store) |
675 | 598 |
|
676 | 599 | if not skip_images: |
|
0 commit comments