(20241126) Upgraded Redis Cache v2. It can now list keys and get the TTL for existing keys.
This commit is contained in:
+54
-1
@@ -60,7 +60,7 @@ import asyncio
|
||||
import datetime
|
||||
|
||||
# For working with datatypes:
|
||||
from typing import Dict, Literal
|
||||
from typing import Dict, Literal, List
|
||||
|
||||
# For debugging:
|
||||
from icecream import IceCreamDebugger
|
||||
@@ -502,6 +502,59 @@ class AsyncGMailClient:
|
||||
# Done here:
|
||||
return success
|
||||
|
||||
# ┳┳┓
|
||||
# ┃┃┃┏┓┏┏┏┓┏┓┏┓┏
|
||||
# ┛ ┗┗ ┛┛┗┻┗┫┗ ┛
|
||||
# ┛
|
||||
|
||||
async def __list_messages_in_page(
|
||||
self,
|
||||
count: int = 100,
|
||||
query: str = None,
|
||||
label_ids: List[str] | str = None,
|
||||
include_spam_and_trash: bool = False,
|
||||
next_page_token: str = None,
|
||||
raise_exception: bool = False
|
||||
):
|
||||
|
||||
# Start by assuming failure:
|
||||
page_messages = None
|
||||
|
||||
try:
|
||||
|
||||
# Standard token-refresh check:
|
||||
await self.__ensure_token()
|
||||
|
||||
# Build the needed params:
|
||||
params_json = {"count": count}
|
||||
if query: params_json["q"] = query
|
||||
if next_page_token: params_json["pageToken"] = next_page_token
|
||||
if label_ids: params_json["labelIds"] = label_ids if isinstance(label_ids, list) else [label_ids]
|
||||
if include_spam_and_trash: params_json["includeSpamTrash"] = include_spam_and_trash
|
||||
|
||||
# Make the API call:
|
||||
if not self._debug_only_errors: self._printer("Listing All Labels.", self.__user_email)
|
||||
api_response = await self.__http_client.get(
|
||||
url = f"https://gmail.googleapis.com/gmail/v1/users/{self.__user_email}/messages",
|
||||
headers = {"Authorization": f"Bearer {self.__credentials.token}"},
|
||||
params = params_json
|
||||
)
|
||||
|
||||
# If the API call failed:
|
||||
if api_response.status_code not in [200]: return labels
|
||||
|
||||
# Else we format the response:
|
||||
labels = {label.pop("name"): label for label in api_response.json().get("labels", [])}
|
||||
|
||||
# In case something goes wrong along the way:
|
||||
except Exception as exception:
|
||||
if raise_exception: raise
|
||||
self._printer(exception)
|
||||
labels = None
|
||||
|
||||
# Done here:
|
||||
return labels
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
|
||||
Reference in New Issue
Block a user