diff options
author | lexicade <jasonnlelong@gmail.com> | 2023-01-27 21:06:30 +0000 |
---|---|---|
committer | lexicade <jasonnlelong@gmail.com> | 2023-01-27 21:06:30 +0000 |
commit | 52801b4de1d63cd01191acf7fcee137977140ec0 (patch) | |
tree | 08271a1f1e3e8060486b6651c67c9934867c648e /ffxiv/pystone/lodestone.py | |
parent | 8df873808c86805624851356f5dea76ec621de23 (diff) |
Diffstat (limited to 'ffxiv/pystone/lodestone.py')
-rw-r--r-- | ffxiv/pystone/lodestone.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ffxiv/pystone/lodestone.py b/ffxiv/pystone/lodestone.py new file mode 100644 index 0000000..3f48c2b --- /dev/null +++ b/ffxiv/pystone/lodestone.py @@ -0,0 +1,39 @@ +from typing import Union, List +from pathlib import Path +from json import loads + +from requests_cache import CachedSession as Session +# from requests import Session + +from pystone.types import MetaDict +from pystone.definition import Definition +from pystone.character import Character + +LODESTONE_BASE_URL = 'finalfantasyxiv.com/lodestone' + + +class Lodestone: + def __init__(self, *, json_base: Union[str, Path]): + if isinstance(json_base, str): + json_base = Path(json_base) + self.json_base: Path = json_base + + # read meta.json + with open(json_base / 'meta.json') as f: + self.meta: MetaDict = loads(f.read()) + self.session = Session() + # self.session.headers.update({ + # 'User-Agent': self.meta['userAgentDesktop'] + # }) + + def get_character_by_id(self, id: Union[str, int]) -> None: + profile_json_files = (self.json_base / 'profile').expanduser().glob('*.json') + definitions: List[Definition] = [] + + for profile in profile_json_files: + url = self.meta['applicableUris'][f'profile/{profile.name}'] + d = Definition(profile, url, session=self.session) + d.process({'id': str(id)}) + definitions.append(d) + + return Character(definitions=definitions) |