wf-worldstate/api.py

34 lines
1.2 KiB
Python
Raw Permalink Normal View History

2022-11-10 16:25:46 +05:00
import requests, json
2023-08-03 13:37:46 +05:00
# API request handler and data access
2022-11-10 16:25:46 +05:00
class WorldState():
def __init__(self):
self.client = requests.Session()
self.ws = {}
self.get_ws()
def get_ws(self):
try:
self.ws = json.loads(self.client.get('https://api.warframestat.us/pc?language=en').text)
except requests.exceptions.ConnectionError:
return False
2023-08-03 13:37:46 +05:00
# aribtrary mapping, some skipped, some not-standard anyway
# better way is probably to do setattr in a loop, but then need to
# change code and handle baro.
# not willing to change it on the off chance much of this is replaced if
# content API becomes useful and names change again
2022-11-10 16:25:46 +05:00
self.fissures = self.ws.get('fissures')
self.invasions = self.ws.get('invasions')
2022-11-10 23:03:50 +05:00
self.sorties = self.ws.get('sortie')
2022-11-10 16:25:46 +05:00
self.archon_hunt = self.ws.get('archonHunt')
self.arbitration = self.ws.get('arbitration')
self.alerts = self.ws.get('alerts')
self.baro_items = self.ws.get('voidTrader').get('inventory')
self.nightwave = self.ws.get('nightwave')
self.events = self.ws.get('events')
self.news = self.ws.get('news')
return True