(20250116) Started upgrading the mail module (to eventually work on cron).
This commit is contained in:
@@ -39,6 +39,13 @@ sys.path.append("..")
|
||||
from pydantic import BaseModel, Field, field_validator, PastDatetime, model_validator
|
||||
from typing import Optional, Literal, Union
|
||||
|
||||
# Models:
|
||||
from models.finstitutions.trading.oauth import (
|
||||
PaperTradingAuth,
|
||||
ZerodhaKiteAuth,
|
||||
ICICIBreezeAuth
|
||||
)
|
||||
|
||||
# My utils:
|
||||
from utils_v2.string import regex
|
||||
from utils_v2.date_time import date_time
|
||||
@@ -75,104 +82,6 @@ REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
class PaperTradingAuth(BaseModel):
|
||||
|
||||
username: str = Field(
|
||||
description = "??",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
password: str = Field(
|
||||
description = "??",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class ZerodhaKiteAuth(BaseModel):
|
||||
|
||||
userId: str = Field(
|
||||
description = "How Zerodha's Kite platform identifies this user.",
|
||||
frozen = True,
|
||||
alias = "clientId"
|
||||
)
|
||||
|
||||
apiKey: str = Field(
|
||||
description = (
|
||||
"The API key of your Kite app. "
|
||||
"This remains constant throughout the life of the app."
|
||||
),
|
||||
frozen = True
|
||||
)
|
||||
|
||||
apiSecret: str = Field(
|
||||
description = (
|
||||
"The API secret of your Kite app. "
|
||||
"This can be changed if you think the security of your app has been compromised."
|
||||
),
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
populate_by_name = True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class ICICIBreezeAuth(BaseModel):
|
||||
|
||||
userId: str = Field(
|
||||
description = "How ICICI's Breeze platform identifies this user.",
|
||||
frozen = True,
|
||||
alias = "clientId"
|
||||
)
|
||||
|
||||
apiKey: str = Field(
|
||||
description = (
|
||||
"The API key of your Breeze app. "
|
||||
"This remains constant throughout the life of the app."
|
||||
),
|
||||
frozen = True
|
||||
)
|
||||
|
||||
apiSecret: str = Field(
|
||||
description = (
|
||||
"The API secret of your Breeze app. "
|
||||
"This can be changed if you think the security of your app has been compromised."
|
||||
),
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
populate_by_name = True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TradingAuthRequestHeaders(BaseModel):
|
||||
|
||||
sessionToken: str = Field(
|
||||
|
||||
@@ -79,45 +79,6 @@ REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
class TradingSymbolListBrokerResponse(BaseModel):
|
||||
|
||||
success: bool = Field(
|
||||
description = "whether, or not, the symbol list request was successful",
|
||||
default = False,
|
||||
frozen = False
|
||||
)
|
||||
|
||||
message: str = Field(
|
||||
description = "a brief message to help debug in failed cases",
|
||||
default = "",
|
||||
frozen = False
|
||||
)
|
||||
|
||||
data: List[TradingSymbol] | None = Field(
|
||||
description = "the actual response from the broker with his list of tradeable symbols",
|
||||
default = None,
|
||||
frozen = False
|
||||
)
|
||||
|
||||
exception: Exception | None = Field(
|
||||
description = "if something goes wrong, the exception will be held here",
|
||||
default = None,
|
||||
frozen = False
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class TradingSymbolListRequestHeaders(BaseModel):
|
||||
|
||||
sessionToken: str = Field(
|
||||
|
||||
@@ -39,6 +39,9 @@ sys.path.append("..")
|
||||
from pydantic import BaseModel, Field, field_validator, PastDatetime, model_validator
|
||||
from typing import Optional, Literal, Union
|
||||
|
||||
# Models:
|
||||
from models.message.chat.auth import TelegramAuth, WhatsAppNimbusAuth
|
||||
|
||||
# My utils:
|
||||
from utils_v2.string import regex
|
||||
from utils_v2.date_time import date_time
|
||||
@@ -75,52 +78,6 @@ REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
class TelegramAuth(BaseModel):
|
||||
|
||||
botToken: str = Field(
|
||||
description = "the token granted by BotFather",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class WhatsAppNimbusAuth(BaseModel):
|
||||
|
||||
apiKey: str = Field(
|
||||
description = "???",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
senderId: str = Field(
|
||||
description = "???",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class ChatAuthRequestHeaders(BaseModel):
|
||||
|
||||
sessionToken: str = Field(
|
||||
@@ -156,98 +156,6 @@ class MailSyncRequestData(BaseModel):
|
||||
return value
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MailSyncOneResult(BaseModel):
|
||||
|
||||
success: bool = Field(
|
||||
description = "whether, or not, the mail was successfully sync'd",
|
||||
default = False
|
||||
)
|
||||
|
||||
message: str | None = Field(
|
||||
description = "a brief message to summarize the result of the process",
|
||||
default = None
|
||||
)
|
||||
|
||||
mailMessage: CoreMessageModel | None = Field(
|
||||
description = "the actual data of the mail; can be null in a successful process if the mail is already sync'd",
|
||||
default = None
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MailSyncManyResults(BaseModel):
|
||||
|
||||
totalCount: int = Field(
|
||||
description = "the total no. of mails that were to be sync'd",
|
||||
default = 0
|
||||
)
|
||||
|
||||
successCount: int = Field(
|
||||
description = "the no. of mails that were successfully sync'd",
|
||||
default = 0
|
||||
)
|
||||
|
||||
failureCount: int = Field(
|
||||
description = "the no. of mails that were successfully sync'd",
|
||||
default = 0
|
||||
)
|
||||
|
||||
message: str = Field(
|
||||
description = "a brief message to summarize the results of the process",
|
||||
default = None
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MailSendOneResult(BaseModel):
|
||||
|
||||
success: bool = Field(
|
||||
description = "whether, or not, the mail was successfully sent",
|
||||
default = False
|
||||
)
|
||||
|
||||
message: str | None = Field(
|
||||
description = "a brief message to summarize the result of the process",
|
||||
default = None
|
||||
)
|
||||
|
||||
mailMessage: CoreMessageModel | None = Field(
|
||||
description = "the actual data of the mail; can be null in a successful process if the mail is already sent",
|
||||
default = None
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** MAIN PROGRAM ***
|
||||
@@ -39,6 +39,9 @@ sys.path.append("..")
|
||||
from pydantic import BaseModel, Field, field_validator, PastDatetime, model_validator
|
||||
from typing import Optional, Literal, Union
|
||||
|
||||
# Models:
|
||||
from models.message.sms.auth import NimbusSMSIndiaAuth, SavvyBulkSMSKenyaAuth
|
||||
|
||||
# My utils:
|
||||
from utils_v2.string import regex
|
||||
from utils_v2.date_time import date_time
|
||||
@@ -75,77 +78,6 @@ REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
class NimbusSMSIndiaAuth(BaseModel):
|
||||
|
||||
entityId: str = Field(
|
||||
description = "the entity id as registered with DLT",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
senderId: str = Field(
|
||||
description = "the 6-char code that you see in your SMS inbox",
|
||||
min_length = 1,
|
||||
frozen = True,
|
||||
examples = ["HDFCBK", "NSESMS", "ZRODHA"]
|
||||
)
|
||||
|
||||
userId: str = Field(
|
||||
description = "the 6-digit id that Nimbus has assigned to you",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
apiKey: str = Field(
|
||||
description = "the key generated through Nimbus's portal",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class SavvyBulkSMSKenyaAuth(BaseModel):
|
||||
|
||||
apiKey: str = Field(
|
||||
description = "the key generated through Savvy's portal",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
partnerId: str = Field(
|
||||
description = "the key generated through Savvy's portal",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
shortCode: str = Field(
|
||||
description = "your short code with Savvy",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class SMSAuthRequestHeaders(BaseModel):
|
||||
|
||||
sessionToken: str = Field(
|
||||
@@ -46,6 +46,12 @@ from utils_v2.date_time import date_time
|
||||
# Models:
|
||||
from models.core.message import CoreMessageModel
|
||||
from utils_v2.sms.models.sms_message import SentSMSMessageModel
|
||||
from models.message.sms.send import (
|
||||
NimbusSMSIndiaMessage,
|
||||
SavvyBulkSMSKenyaMessage,
|
||||
SMSSendOneResult,
|
||||
SMSSendManyResults
|
||||
)
|
||||
|
||||
# To work with date and time:
|
||||
import datetime
|
||||
@@ -82,75 +88,6 @@ REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
class NimbusSMSIndiaMessage(BaseModel):
|
||||
|
||||
recipientNo: str = Field(
|
||||
description = "the phone no. of the target recipient",
|
||||
pattern = r"\+?\d{0,3}\s*\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
text: str = Field(
|
||||
description = "the actual text that you want to send",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
templateId: str = Field(
|
||||
description = "the id of the template that you are trying to use to send the message",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@field_validator("recipientNo", mode = "before")
|
||||
def validate_contact_nos(cls, value):
|
||||
value = regex.replace(text = str(value), pattern = r"[^\d]", substitute_text = "")
|
||||
if len(value) > 10: value = regex.replace(text = str(value), pattern = r"^(91)", substitute_text = "")
|
||||
value = regex.find_first(text = str(value), pattern = r"^[\d]{10}")
|
||||
return value
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class SavvyBulkSMSKenyaMessage(BaseModel):
|
||||
|
||||
recipientNo: str = Field(
|
||||
description = "the phone no. of the target recipient",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
text: str = Field(
|
||||
description = "the actual text that you want to send",
|
||||
min_length = 1,
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class SMSSendRequestHeaders(BaseModel):
|
||||
|
||||
sessionToken: str | None = Field(
|
||||
@@ -211,74 +148,6 @@ class SMSSendRequestData(BaseModel):
|
||||
return [] if value is None else value
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class SMSSendOneResult(BaseModel):
|
||||
|
||||
success: bool = Field(
|
||||
description = "whether, or not, the sms was successfully sent",
|
||||
default = False
|
||||
)
|
||||
|
||||
message: str | None = Field(
|
||||
description = "a brief message to summarize the result of the process",
|
||||
default = None
|
||||
)
|
||||
|
||||
smsMessage: NimbusSMSIndiaMessage | SavvyBulkSMSKenyaMessage = Field(
|
||||
description = "the actual data of the sms",
|
||||
default = None
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class SMSSendManyResults(BaseModel):
|
||||
|
||||
totalCount: int = Field(
|
||||
description = "the total no. of mails that were to be sync'd",
|
||||
default = 0
|
||||
)
|
||||
|
||||
successCount: int = Field(
|
||||
description = "the no. of mails that were successfully sync'd",
|
||||
default = 0
|
||||
)
|
||||
|
||||
failureCount: int = Field(
|
||||
description = "the no. of mails that were successfully sync'd",
|
||||
default = 0
|
||||
)
|
||||
|
||||
message: str = Field(
|
||||
description = "a brief message to summarize the results of the process",
|
||||
default = None
|
||||
)
|
||||
|
||||
smsMessages: List[CoreMessageModel] = Field(
|
||||
description = "the actual data of the sms",
|
||||
default = []
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** MAIN PROGRAM ***
|
||||
@@ -288,15 +157,4 @@ class SMSSendManyResults(BaseModel):
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
from utils_v2.string import json
|
||||
|
||||
my_request = SMSSendRequestData(
|
||||
tokenId = "670f580d7cda4ebc1adc3444",
|
||||
message = NimbusSMSIndiaMessage(
|
||||
recipientNo = "+.9.1 ---> 93261 3642fgnn193261",
|
||||
text = "Hello, Nimbus!",
|
||||
templateId = "12345678"
|
||||
)
|
||||
)
|
||||
|
||||
print("NIMBUS SMS API MODEL:", json.to_string(my_request.model_dump(), default = str))
|
||||
pass
|
||||
Reference in New Issue
Block a user