(20250730) - ADDED - Google Places API for and paper trading update api with required fies and changes.
This commit is contained in:
@@ -117,7 +117,7 @@ class TradingAuthRequestData(BaseModel):
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
extra = "allow"
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
@@ -136,6 +136,11 @@ class TradingAuthRequestData(BaseModel):
|
||||
raise ValueError(f"incorrect 'auth' for selected client '{client}'")
|
||||
return values
|
||||
|
||||
# ADDED BY OMKAR - 2025-07-29 --------------------------------------------------------------------------------------
|
||||
|
||||
def get(self, key, default=None):
|
||||
return getattr(self, key, default)
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
|
||||
@@ -0,0 +1,390 @@
|
||||
"""
|
||||
|
||||
AUTHOR:
|
||||
|
||||
Omkar Khandare
|
||||
|
||||
DATE:
|
||||
|
||||
Monday, 7th July., 2025.
|
||||
|
||||
OBJECTIVE:
|
||||
|
||||
To provide a structure to search places.
|
||||
|
||||
REFERENCES:
|
||||
|
||||
N/A
|
||||
|
||||
DOWNLOADS:
|
||||
|
||||
N/A
|
||||
|
||||
"""
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** IMPORT ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
import io
|
||||
|
||||
# To make sibling directories accessible for imports:
|
||||
import sys
|
||||
sys.path.append(".")
|
||||
sys.path.append("..")
|
||||
|
||||
# For making data behaviour_models:
|
||||
from pydantic import BaseModel, Field, field_validator, PastDatetime, EmailStr, model_validator
|
||||
from typing import Union, Literal, List
|
||||
|
||||
# My utils:
|
||||
from utils_v2.string import json
|
||||
from utils_v2.string import regex
|
||||
from utils_v2.date_time import date_time
|
||||
|
||||
# To work with date and time:
|
||||
import datetime
|
||||
|
||||
# To work with Base64 data:
|
||||
import base64
|
||||
|
||||
# To work with MongoDB:
|
||||
from bson.objectid import ObjectId
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** MACROS / ONE-TIME INIT ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
# RegEx Patterns:
|
||||
REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** VARIABLES ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
# --- Nothing Yet
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** FUNCTIONS ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
class PlacesRequestHeaders(BaseModel):
|
||||
|
||||
sessionToken: str = Field(
|
||||
description = "the session token of the user who is requesting the service",
|
||||
pattern = REGEX_SESSION_TOKEN,
|
||||
frozen = True,
|
||||
default = None,
|
||||
alias = "X-Session-Token"
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "allow"
|
||||
|
||||
def model_dump(self, *args, **kwargs):
|
||||
return super().model_dump(*args, by_alias = True, **kwargs)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MailSendPlainText(BaseModel):
|
||||
|
||||
content: str = Field(
|
||||
description = "The string to add to the mail as plain text.",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MailSendHTMLText(BaseModel):
|
||||
|
||||
content: str = Field(
|
||||
description = "The HTML string to add to the mail.",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MailSendAttachment(BaseModel):
|
||||
|
||||
content: str | io.BytesIO = Field(
|
||||
description = "The Base64 string to add to the mail as a file.",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
fileName: str = Field(
|
||||
description = "The name of the file that will be downloaded when the recipient tries to access the content.",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@field_validator("content", mode = "before")
|
||||
def parse_base64_file(cls, value):
|
||||
if isinstance(value, str):
|
||||
base64_parts = value.split(",", 1)
|
||||
if len(base64_parts) == 1: header, base64_string = None, base64_parts[0]
|
||||
else: header, base64_string = base64_parts[0], base64_parts[1]
|
||||
value = io.BytesIO(base64.b64decode(base64_string))
|
||||
return value
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MailSendInlineImage(BaseModel):
|
||||
|
||||
content: str | io.BytesIO = Field(
|
||||
description = "The image content to add to the mail as an inline image file.",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
fileName: str = Field(
|
||||
description = "The name of the file that will be downloaded when the recipient tries to access the content.",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
cid: str | None = Field(
|
||||
description = "A custom Content-Id to assign to the inline attachment.",
|
||||
frozen = True,
|
||||
default = None
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@field_validator("content", mode = "before")
|
||||
def parse_base64_file(cls, value):
|
||||
if isinstance(value, str):
|
||||
base64_parts = value.split(",", 1)
|
||||
if len(base64_parts) == 1: header, base64_string = None, base64_parts[0]
|
||||
else: header, base64_string = base64_parts[0], base64_parts[1]
|
||||
value = io.BytesIO(base64.b64decode(base64_string))
|
||||
return value
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class MailSendPart(BaseModel):
|
||||
|
||||
type: Literal["plain", "html", "attachment", "inline"] = Field(
|
||||
description = "The kind of part this is.",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
part: dict | Union[
|
||||
MailSendPlainText, MailSendHTMLText, # ...... Textual content.
|
||||
MailSendAttachment, MailSendInlineImage # ... Media content.
|
||||
] = Field(
|
||||
description = "One of the structured types of data that can be put in the mail.",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@model_validator(mode = "before")
|
||||
def ensure_harmony(cls, values):
|
||||
kind_map = {
|
||||
"plain": MailSendPlainText,
|
||||
"html": MailSendHTMLText,
|
||||
"attachment": MailSendAttachment,
|
||||
"inline": MailSendInlineImage,
|
||||
}
|
||||
part_dict = values["part"] if isinstance(values["part"], dict) else values["part"].model_dump()
|
||||
values["part"] = kind_map[values["type"]](**part_dict)
|
||||
return values
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
class PlacesNearbyRequestData(BaseModel):
|
||||
|
||||
tokenKey: ObjectId = Field(
|
||||
description = "The identifier (Mongo ObjectId) of the account from which the mail has to be sent.",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
latitude: float = Field(
|
||||
description= "The Location latitude points",
|
||||
frozen= True
|
||||
)
|
||||
|
||||
longitude: float = Field(
|
||||
description= "The Location longitude points",
|
||||
frozen=True
|
||||
)
|
||||
|
||||
radius: float = Field(
|
||||
description= "The radius point of location your not provided by default will be 500 meter",
|
||||
frozen=True,
|
||||
default=500
|
||||
)
|
||||
|
||||
max_count: int = Field(
|
||||
description= "Max count for get result counts",
|
||||
frozen=True,
|
||||
default=20
|
||||
)
|
||||
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@field_validator("tokenKey", mode = "before")
|
||||
def parse_oid(cls, value):
|
||||
try: value = ObjectId(value)
|
||||
except: pass
|
||||
return value
|
||||
|
||||
# @field_validator("to", "cc", "bcc", mode = "before")
|
||||
# def parse_recipients(cls, value):
|
||||
#
|
||||
# # Ensure that we are working with some kind of list:
|
||||
# if value is None: value = []
|
||||
# if isinstance(value, str): value = [value]
|
||||
#
|
||||
# # # Ensure that all values of the list look like valid mails:
|
||||
# # for index, email_id in enumerate(value):
|
||||
# # if not regex.match(
|
||||
# # text = email_id,
|
||||
# # pattern = regex.REGEX_START + regex.REGEX_EMAIL_ID + regex.REGEX_END,
|
||||
# # case_sensitive = False,
|
||||
# # ): raise ValueError(f"'{email_id}' does not seem to be a valid e-mail id.")
|
||||
#
|
||||
# # Done here:
|
||||
# return value
|
||||
|
||||
# ----------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class PlacesTextSearchRequestData(BaseModel):
|
||||
|
||||
tokenKey: ObjectId = Field(
|
||||
description = "The identifier (Mongo ObjectId) of the account from which the mail has to be sent.",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
textQuery: float = Field(
|
||||
description= "Text Query for find places",
|
||||
frozen= True
|
||||
)
|
||||
|
||||
max_count: int = Field(
|
||||
description= "Max count for get result counts",
|
||||
frozen=True,
|
||||
default=20
|
||||
)
|
||||
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@field_validator("tokenKey", mode = "before")
|
||||
def parse_oid(cls, value):
|
||||
try: value = ObjectId(value)
|
||||
except: pass
|
||||
return value
|
||||
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** MAIN PROGRAM ***
|
||||
# ***** ****
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
pass
|
||||
Reference in New Issue
Block a user