add own mini ffxivapi wrapper
This commit is contained in:
74
scripts/lib/ffxivapi.py
Normal file
74
scripts/lib/ffxivapi.py
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
from .ffxivclasses import *
|
||||||
|
import requests as req
|
||||||
|
import json
|
||||||
|
|
||||||
|
class FFXIVAPI:
|
||||||
|
__author__ = 'Anima'
|
||||||
|
__version__ = '0.0.1'
|
||||||
|
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self.BASEURL : str = 'https://xivapi.com'
|
||||||
|
|
||||||
|
class Character(FFXIVAPI):
|
||||||
|
__version__ = '0.0.1'
|
||||||
|
|
||||||
|
def __init__(self, charid: int = None, charname: tuple = None) -> None:
|
||||||
|
"""
|
||||||
|
Final Fantasy XIV Character
|
||||||
|
|
||||||
|
Use one of:
|
||||||
|
- charid (from lodestone)
|
||||||
|
- charname tuple with (charname, world)
|
||||||
|
"""
|
||||||
|
super().__init__()
|
||||||
|
self.BASEURL : str = self.BASEURL + '/character'
|
||||||
|
self.CHARID : str = str(charid)
|
||||||
|
if not charid and isinstance(charname, tuple):
|
||||||
|
self.search_char(charname)
|
||||||
|
if self.CHARID:
|
||||||
|
self.get_char()
|
||||||
|
self.CLASSES : list = [
|
||||||
|
DarkKnight(), Gunbreaker(), Paladin(), Warrior(),
|
||||||
|
Astrologian(), Sage(), Sholar(), WhiteMage(),
|
||||||
|
Dragoon(), Monk(), Ninja(), Samurai(), Reaper(),
|
||||||
|
Bard(), Dancer(), Machinist(),
|
||||||
|
BlackMage(), RedMage(), Summoner(), BlueMage(),
|
||||||
|
Botanist(), Fisher(), Miner(),
|
||||||
|
Alchemist(), Armorer(), Blacksmith(), Carpenter(),
|
||||||
|
Culinarian(), Goldsmith(), Leatherworker(), Weaver()
|
||||||
|
]
|
||||||
|
|
||||||
|
def search_char(self, char) -> None:
|
||||||
|
query = f'/search?name={char[0].replace(" ", "%20")}&server={char[1]}'
|
||||||
|
result = req.get(self.BASEURL + query)
|
||||||
|
apidata = json.loads(result.text)
|
||||||
|
if len(apidata['Results']) == 1:
|
||||||
|
self.CHARID = str(apidata['Results'][0]['ID'])
|
||||||
|
|
||||||
|
def get_char(self) -> None:
|
||||||
|
result = req.get(self.BASEURL + '/' + self.CHARID)
|
||||||
|
self.APIDATA = json.loads(result.text)
|
||||||
|
self.NAME = self.APIDATA['Character']['Name']
|
||||||
|
self.WORLD = self.APIDATA['Character']['Server']
|
||||||
|
self.FC = self.APIDATA['Character']['FreeCompanyName']
|
||||||
|
self.FCID = self.APIDATA['Character']['FreeCompanyId']
|
||||||
|
|
||||||
|
def map_classes(self):
|
||||||
|
for apicls in self.APIDATA['Character']['ClassJobs']:
|
||||||
|
for cls in self.CLASSES:
|
||||||
|
if apicls['JobID'] == cls.FFXIVAPIID:
|
||||||
|
if apicls['Level'] > 0:
|
||||||
|
cls.LEVEL = apicls['Level']
|
||||||
|
break
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
# anima = Character(29859367)
|
||||||
|
anima = Character(charname=('Anima Ira', 'Omega'))
|
||||||
|
|
||||||
|
anima.map_classes()
|
||||||
|
sum = 0
|
||||||
|
for cls in anima.CLASSES:
|
||||||
|
if isinstance(cls, (Heal, Tank)):
|
||||||
|
sum += cls.LEVEL
|
||||||
|
print(cls.ROLE, cls.NAME, cls.LEVEL)
|
||||||
|
print(sum)
|
||||||
Reference in New Issue
Block a user