Skip to content

Commit

Permalink
🐛 v2.5.3-1285 (#54)
Browse files Browse the repository at this point in the history
Signed-off-by: Ludy87 <Ludy87@users.noreply.github.com>

Signed-off-by: Ludy87 <Ludy87@users.noreply.github.com>
  • Loading branch information
Ludy87 authored Jan 23, 2023
1 parent 7ec4238 commit e8d3338
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 49 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import setuptools
import configparser

with open("README.md", "r") as fh:
with open("README.md") as fh:
long_description = fh.read()

with open("./src/pyxplora_api/const.py") as f:
Expand Down
2 changes: 1 addition & 1 deletion src/pyxplora_api/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "2.5.2"
VERSION = "2.5.3"
VERSION_APP = "1285"
API_KEY = "fc45d50304511edbf67a12b93c413b6a"
API_SECRET = "1e9b6fe0327711ed959359c157878dcb"
Expand Down
10 changes: 8 additions & 2 deletions src/pyxplora_api/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import Optional

from dataclasses_json import DataClassJsonMixin, dataclass_json
Expand Down Expand Up @@ -55,7 +55,13 @@ class SimpleChat(DataClassJsonMixin):
@dataclass_json
@dataclass
class ChatsNew(DataClassJsonMixin):
list: Optional[list[SimpleChat]]
list: Optional[list[SimpleChat]] = field(default_factory=list[SimpleChat])

def get_list(self) -> list[SimpleChat] | None:
try:
return self.list
except AttributeError:
return None


@dataclass_json
Expand Down
49 changes: 27 additions & 22 deletions src/pyxplora_api/pyxplora_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def getWatchUserContacts(self, wuid: str) -> list[dict[str, Any]]:
_LOGGER.debug(error)
dataOk = contacts
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return contacts

Expand Down Expand Up @@ -213,7 +213,7 @@ def getWatchAlarm(self, wuid: str) -> list[dict[str, Any]]:
_LOGGER.debug(error)
dataOk = alarms
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return alarms

Expand Down Expand Up @@ -271,7 +271,7 @@ def loadWatchLocation(self, wuid: str = "", withAsk: bool = True) -> dict[str, A
_LOGGER.debug(error)
dataOk = watch_location
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return watch_location

Expand Down Expand Up @@ -302,7 +302,7 @@ def getWatchOnlineStatus(self, wuid: str) -> str:
_LOGGER.debug(error)
dataOk = asktrack_raw
if dataOk is WatchOnlineStatus.UNKNOWN:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return asktrack_raw.value

Expand Down Expand Up @@ -339,13 +339,15 @@ def getWatchChats(
"data_text": chat.data.text,
"data_sender_name": chat.data.sender_name,
"create": datetime.fromtimestamp(chat.create).strftime("%Y-%m-%d %H:%M:%S"),
"delete_flag": chat.data.delete_flag,
"emoticon_id": chat.data.emoticon_id,
}
)
except Error as error:
_LOGGER.debug(error)
dataOk = chats
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return chats

Expand All @@ -360,20 +362,23 @@ def getWatchChatsRaw(
try:
chats: Chats = Chats.from_dict(self._gqlHandler.chats(wuid, offset, limit, msgId))

oldChatList: list[SimpleChat] = chats.chatsNew.list
newChatList: list[SimpleChat] = []
for chat in oldChatList:
chat.data.emoticon_id = Emoji["M%s" % chat.data.emoticon_id].value
if show_del_msg:
newChatList.append(chat)
elif chat.data.delete_flag == 0:
newChatList.append(chat)
_chatsNew = ChatsNew(newChatList).to_dict()
chatsNew: ChatsNew = ChatsNew.from_dict(chats.chatsNew)

oldChatList: list[SimpleChat] = chatsNew.get_list()
if oldChatList:
newChatList: list[SimpleChat] = []
for chat in oldChatList:
chat.data.emoticon_id = Emoji["M%s" % chat.data.emoticon_id].value
if show_del_msg:
newChatList.append(chat)
elif chat.data.delete_flag == 0:
newChatList.append(chat)
_chatsNew = ChatsNew(newChatList).to_dict()
except Error as error:
_LOGGER.debug(error)
dataOk = _chatsNew
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return _chatsNew

Expand Down Expand Up @@ -436,7 +441,7 @@ def getWatchSafeZones(self, wuid: str) -> list[dict[str, Any]]:
_LOGGER.debug(error)
dataOk = safe_zones
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return safe_zones

Expand Down Expand Up @@ -475,7 +480,7 @@ def getSilentTime(self, wuid: str) -> list[dict[str, Any]]:
_LOGGER.debug(error)
dataOk = school_silent_mode
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return school_silent_mode

Expand All @@ -495,7 +500,7 @@ def setEnableSilentTime(self, silentId: str) -> bool:
_LOGGER.debug(error)
dataOk = _raw
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return bool(_raw)

Expand All @@ -515,7 +520,7 @@ def setDisableSilentTime(self, silentId: str) -> bool:
_LOGGER.debug(error)
dataOk = _raw
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return bool(_raw)

Expand Down Expand Up @@ -547,7 +552,7 @@ def setEnableAlarmTime(self, alarmId: str) -> bool:
_LOGGER.debug(error)
dataOk = _raw
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return bool(_raw)

Expand All @@ -567,7 +572,7 @@ def setDisableAlarmTime(self, alarmId: str) -> bool:
_LOGGER.debug(error)
dataOk = _raw
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return bool(_raw)

Expand Down Expand Up @@ -633,7 +638,7 @@ def getWatches(self, wuid: str) -> dict[str, Any]:
_LOGGER.debug(error)
dataOk = watches
if not dataOk:
self._logoff()
# self._logoff()
self.delay(self.retryDelay)
return watches

Expand Down
52 changes: 29 additions & 23 deletions src/pyxplora_api/pyxplora_api_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def getWatchUserContacts(self, wuid: str) -> list[dict[str, Any]]:
_LOGGER.debug(error)
dataOk = contacts
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return contacts

Expand Down Expand Up @@ -209,7 +209,7 @@ async def getWatchAlarm(self, wuid: str) -> list[dict[str, Any]]:
_LOGGER.debug(error)
dataOk = alarms
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return alarms

Expand Down Expand Up @@ -267,7 +267,7 @@ async def loadWatchLocation(self, wuid: str = "", withAsk: bool = True) -> dict[
_LOGGER.debug(error)
dataOk = watch_location
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return watch_location

Expand Down Expand Up @@ -298,7 +298,7 @@ async def getWatchOnlineStatus(self, wuid: str) -> str:
_LOGGER.debug(error)
dataOk = asktrack_raw
if dataOk is WatchOnlineStatus.UNKNOWN:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return asktrack_raw.value

Expand Down Expand Up @@ -335,41 +335,47 @@ async def getWatchChats(
"data_text": chat.data.text,
"data_sender_name": chat.data.sender_name,
"create": datetime.fromtimestamp(chat.create).strftime("%Y-%m-%d %H:%M:%S"),
"delete_flag": chat.data.delete_flag,
"emoticon_id": chat.data.emoticon_id,
}
)
except Error as error:
_LOGGER.debug(error)
dataOk = chats
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return chats

async def getWatchChatsRaw(
self, wuid: str, offset: int = 0, limit: int = 0, msgId: str = "", show_del_msg: bool = True
) -> dict[str, Any]:
retryCounter = 0
dataOk: dict[str, Any] = []
dataOk: dict[str, Any] = {}
_chatsNew: dict[str, Any] = {}
while not dataOk and (retryCounter < self.maxRetries + 2):
retryCounter += 1
try:
chats: Chats = Chats.from_dict(await self._gqlHandler.chats_a(wuid, offset, limit, msgId))

oldChatList: list[SimpleChat] = chats.chatsNew.list
newChatList: list[SimpleChat] = []
for chat in oldChatList:
chat.data.emoticon_id = Emoji["M%s" % chat.data.emoticon_id].value
if show_del_msg:
newChatList.append(chat)
elif chat.data.delete_flag == 0:
newChatList.append(chat)
_chatsNew = ChatsNew(newChatList).to_dict()
chatsNew: ChatsNew = ChatsNew.from_dict(chats.chatsNew)
chatsNew.__delattr__("list")

oldChatList: list[SimpleChat] = chatsNew.get_list()
if oldChatList:
newChatList: list[SimpleChat] = []
for chat in oldChatList:
chat.data.emoticon_id = Emoji["M%s" % chat.data.emoticon_id].value
if show_del_msg:
newChatList.append(chat)
elif chat.data.delete_flag == 0:
newChatList.append(chat)
_chatsNew = ChatsNew(newChatList).to_dict()
except Error as error:
_LOGGER.debug(error)
dataOk = _chatsNew
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return _chatsNew

Expand Down Expand Up @@ -432,7 +438,7 @@ async def getWatchSafeZones(self, wuid: str) -> list[dict[str, Any]]:
_LOGGER.debug(error)
dataOk = safe_zones
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return safe_zones

Expand Down Expand Up @@ -471,7 +477,7 @@ async def getSilentTime(self, wuid: str) -> list[dict[str, Any]]:
_LOGGER.debug(error)
dataOk = school_silent_mode
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return school_silent_mode

Expand All @@ -491,7 +497,7 @@ async def setEnableSilentTime(self, silentId: str) -> bool:
_LOGGER.debug(error)
dataOk = _raw
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return bool(_raw)

Expand All @@ -511,7 +517,7 @@ async def setDisableSilentTime(self, silentId: str) -> bool:
_LOGGER.debug(error)
dataOk = _raw
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return bool(_raw)

Expand Down Expand Up @@ -543,7 +549,7 @@ async def setEnableAlarmTime(self, alarmId: str) -> bool:
_LOGGER.debug(error)
dataOk = _raw
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return bool(_raw)

Expand All @@ -563,7 +569,7 @@ async def setDisableAlarmTime(self, alarmId: str) -> bool:
_LOGGER.debug(error)
dataOk = _raw
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return bool(_raw)

Expand Down Expand Up @@ -629,7 +635,7 @@ async def getWatches(self, wuid: str) -> dict[str, Any]:
_LOGGER.debug(error)
dataOk = watches
if not dataOk:
self._logoff()
# self._logoff()
await sleep(self.retryDelay)
return watches

Expand Down

0 comments on commit e8d3338

Please sign in to comment.