diff --git a/spond/spond.py b/spond/spond.py index 9eb71a5..7c493c4 100644 --- a/spond/spond.py +++ b/spond/spond.py @@ -1,10 +1,13 @@ #!/usr/bin/env python3 from datetime import datetime -from typing import List, Optional +from typing import TYPE_CHECKING, List, Optional import aiohttp +if TYPE_CHECKING: + from datetime import datetime + class AuthenticationError(Exception): pass @@ -12,12 +15,12 @@ class AuthenticationError(Exception): class Spond: + API_BASE_URL = "https://api.spond.com/core/v1/" DT_FORMAT = "%Y-%m-%dT00:00:00.000Z" def __init__(self, username, password): self.username = username self.password = password - self.api_url = "https://api.spond.com/core/v1/" self.clientsession = aiohttp.ClientSession(cookie_jar=aiohttp.CookieJar()) self.chat_url = None self.auth = None @@ -34,7 +37,7 @@ def auth_headers(self): } async def login(self): - login_url = f"{self.api_url}login" + login_url = f"{self.API_BASE_URL}login" data = {"email": self.username, "password": self.password} async with self.clientsession.post(login_url, json=data) as r: login_result = await r.json() @@ -43,7 +46,7 @@ async def login(self): err_msg = f"Login failed. Response received: {login_result}" raise AuthenticationError(err_msg) - api_chat_url = f"{self.api_url}chat" + api_chat_url = f"{self.API_BASE_URL}chat" headers = { "content-type": "application/json", "Authorization": f"Bearer {self.token}", @@ -76,7 +79,7 @@ async def get_groups(self): list of dict Groups; each group is a dict. """ - url = f"{self.api_url}groups/" + url = f"{self.API_BASE_URL}groups/" async with self.clientsession.get(url, headers=self.auth_headers) as r: self.groups = await r.json() return self.groups @@ -286,7 +289,7 @@ async def get_events( list of dict Events; each event is a dict. """ - url = f"{self.api_url}sponds/" + url = f"{self.API_BASE_URL}sponds/" params = { "max": str(max_events), "scheduled": str(include_scheduled), @@ -361,7 +364,7 @@ async def update_event(self, uid, updates: dict): if event["id"] == uid: break - url = f"{self.api_url}sponds/{uid}" + url = f"{self.API_BASE_URL}sponds/{uid}" base_event = { "heading": None, @@ -403,9 +406,9 @@ async def update_event(self, uid, updates: dict): } for key in base_event: - if event.get(key) != None and not updates.get(key): + if event.get(key) is not None and not updates.get(key): base_event[key] = event[key] - elif updates.get(key) != None: + elif updates.get(key) is not None: base_event[key] = updates[key] data = dict(base_event)