mirror of
https://github.com/Xevion/the-office.git
synced 2025-12-15 08:13:29 -06:00
character name separation and character.json saving, refactor character ID generation to helpers
This commit is contained in:
@@ -9,6 +9,7 @@ import re
|
||||
import sys
|
||||
import time
|
||||
from collections import defaultdict
|
||||
from pprint import pprint
|
||||
from typing import List, Optional, Tuple, Union
|
||||
|
||||
import click
|
||||
@@ -16,9 +17,8 @@ import enlighten
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from server.helpers import algolia_transform
|
||||
|
||||
sys.path[0] += '\\..'
|
||||
from server.helpers import algolia_transform, character_id
|
||||
from server.process import DATA_DIR, get_appearances, get_episodes, get_filepath, load_file, \
|
||||
save_file, sleep_from, \
|
||||
verify_episode
|
||||
@@ -389,7 +389,15 @@ def character():
|
||||
data = load_file(os.path.join(DATA_DIR, 'algolia.json'), True)
|
||||
key_list = [('speaker',), ('text',), ('season',), ('episode_rel', 'episode'), ('section_rel', 'scene'),
|
||||
('quote_rel', 'quote')]
|
||||
master = map(lambda item: algolia_transform(item, key_list), filter(lambda: True, data))
|
||||
master = map(lambda item: algolia_transform(item, key_list), filter(lambda item: True, data))
|
||||
|
||||
# Separate the quotes based on speaker
|
||||
char_data = defaultdict(list)
|
||||
for quote in master:
|
||||
char_data[character_id(quote['speaker'])].append(quote)
|
||||
|
||||
# Save to characters.json
|
||||
save_file(os.path.join(DATA_DIR, 'characters.json'), char_data, True)
|
||||
|
||||
|
||||
@build.command('final')
|
||||
|
||||
@@ -50,3 +50,10 @@ def algolia_transform(old_dictionary: dict, key_list: List[Tuple[str, Optional[s
|
||||
new_dictionary[keyItem[0]] = old_dictionary[keyItem[0]]
|
||||
|
||||
return new_dictionary
|
||||
|
||||
|
||||
def is_main_character(name: str) -> bool:
|
||||
return None
|
||||
|
||||
def character_id(name: str) -> str:
|
||||
return '-'.join(name.split(' ')).lower()
|
||||
|
||||
@@ -117,13 +117,6 @@ def get_appearances(season, episode) -> Optional[List[Dict[str, Union[int, str]]
|
||||
for scene in scenes:
|
||||
for quote in scene.get('quotes', []):
|
||||
characters[quote.get('speaker')] += 1
|
||||
characters = [{'name': character, 'appearances': appearances, 'id': '-'.join(character.split(' ')).lower()}
|
||||
characters = [{'name': character, 'appearances': appearances, 'id': character_id(character)}
|
||||
for character, appearances in characters.items()]
|
||||
return list(sorted(characters, key=lambda item: item['appearances'], reverse=True))
|
||||
|
||||
def get_character(character):
|
||||
"""
|
||||
Retrieves a character's appearances from every season and episode available.
|
||||
:param character: The character's name
|
||||
:return: A list of dictionary quotes including reference IDs
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user