Package moex
Expand source code
# -*- coding: utf-8 -*-
__author__ = "Michael R. Kisel"
__license__ = "MIT"
__version__ = "1.0.0"
__maintainer__ = "Michael R. Kisel"
__email__ = "deploy-me@yandex.ru"
__status__ = "Development"
__all__ = (
"AIOMoex",
"HandlersSearchError",
"TemplateRenderError",
"TemplateSearchError",
"URL",
"API"
)
from moex.api import AIOMoex
from moex.exceptions import (
HandlersSearchError,
TemplateRenderError,
TemplateSearchError
)
from moex.templates import URL, API
Sub-modules
moex.api
moex.data_classes
moex.design
moex.exceptions
moex.handlers
moex.meta
moex.templates
moex.utils
Classes
class AIOMoex
-
API interface for MoscowExchange
Expand source code
class AIOMoex: """API interface for MoscowExchange """ def __repr__(self): """Return AIOMoex representation Returns ------- str AIOMoex representation """ try: return f"{self}(handler={self.__handler}, templates={self.templates})" except AttributeError: return f"{self}()" def __str__(self): """Str method Returns ------- str String representation """ return self.__class__.__name__ @property def templates(self): """Return set of templates identifieres Returns ------- set Templates identifieres """ return self.__templates_repository.ids def render_url(self, template_id, **template_vars): """Render url with jinja Parameters ---------- template_id : int Template's identifier Returns ------- str Rendered url """ return self.__templates_repository.render_template(template_id, **template_vars) def find_template(self, search_pattern): """Find templates by pattern Parameters ---------- search_pattern : str Regex or usual string Returns ------- generator Templates generator """ return self.__templates_repository.find_template_id(search_pattern) def get_template(self, template_id): """Get template by template identifier Parameters ---------- template_id : int Template's identifier Returns ------- Template Template dataclass """ return self.__templates_repository.get_template(template_id) def show_templates(self): """Print table with templates identifiers and addresses """ doc_table = CliDesigner.get_table("ID", "URI TEMPLATE") with Live(doc_table, refresh_per_second=6): for template_id in self.templates: doc_table.add_row( f"{CliDesigner.random_color()}{template_id}", f"{CliDesigner.random_color()}{self.get_template(template_id=template_id).path}" ) sleep(.321) async def show_template_doc(self, session, template_id): """Print docs from official web site Parameters ---------- session : aiohttp.ClientSession Client session template_id : int Template's identifier """ await self.__templates_repository.show_template_doc(session, template_id) async def execute(self, session, url, **params): """Call requested uri Parameters ---------- session : aiohttp.ClientSession Client session url : str Api url Returns ------- Any Dataclass instance """ return await self.__handler.execute(session=session, url=url, **params) async def load(self, session, output_format): """Load required data Parameters ---------- session : aiohttp.ClientSession Client session output_format : str Handler's format """ handlers = self.__load_handlers() self.__templates_repository = await self.__load_templates(session) self.__handler = handlers.create(output_format=output_format) @staticmethod async def __load_templates(session): """Load uri templates from official web site Parameters ---------- session : aiohttp.ClientSession Client session Returns ------- TemplatesRepository Repository of templates """ templates_repository = TemplatesRepository() await templates_repository.load_data(session) return templates_repository @staticmethod def __load_handlers(): """Load available handlers Returns ------- Handlers Handlers factory """ handlers = Handlers() for handler in available_handlers: handlers.register(handler.EXTENSION, handler) return handlers
Instance variables
var templates
-
Return set of templates identifieres
Returns
set
- Templates identifieres
Expand source code
@property def templates(self): """Return set of templates identifieres Returns ------- set Templates identifieres """ return self.__templates_repository.ids
Methods
async def execute(self, session, url, **params)
-
Call requested uri
Parameters
session
:aiohttp.ClientSession
- Client session
url
:str
- Api url
Returns
Any
- Dataclass instance
Expand source code
async def execute(self, session, url, **params): """Call requested uri Parameters ---------- session : aiohttp.ClientSession Client session url : str Api url Returns ------- Any Dataclass instance """ return await self.__handler.execute(session=session, url=url, **params)
def find_template(self, search_pattern)
-
Find templates by pattern
Parameters
search_pattern
:str
- Regex or usual string
Returns
generator
- Templates generator
Expand source code
def find_template(self, search_pattern): """Find templates by pattern Parameters ---------- search_pattern : str Regex or usual string Returns ------- generator Templates generator """ return self.__templates_repository.find_template_id(search_pattern)
def get_template(self, template_id)
-
Get template by template identifier
Parameters
template_id
:int
- Template's identifier
Returns
Template
- Template dataclass
Expand source code
def get_template(self, template_id): """Get template by template identifier Parameters ---------- template_id : int Template's identifier Returns ------- Template Template dataclass """ return self.__templates_repository.get_template(template_id)
async def load(self, session, output_format)
-
Load required data
Parameters
session
:aiohttp.ClientSession
- Client session
output_format
:str
- Handler's format
Expand source code
async def load(self, session, output_format): """Load required data Parameters ---------- session : aiohttp.ClientSession Client session output_format : str Handler's format """ handlers = self.__load_handlers() self.__templates_repository = await self.__load_templates(session) self.__handler = handlers.create(output_format=output_format)
def render_url(self, template_id, **template_vars)
-
Render url with jinja
Parameters
template_id
:int
- Template's identifier
Returns
str
- Rendered url
Expand source code
def render_url(self, template_id, **template_vars): """Render url with jinja Parameters ---------- template_id : int Template's identifier Returns ------- str Rendered url """ return self.__templates_repository.render_template(template_id, **template_vars)
async def show_template_doc(self, session, template_id)
-
Print docs from official web site
Parameters
session
:aiohttp.ClientSession
- Client session
template_id
:int
- Template's identifier
Expand source code
async def show_template_doc(self, session, template_id): """Print docs from official web site Parameters ---------- session : aiohttp.ClientSession Client session template_id : int Template's identifier """ await self.__templates_repository.show_template_doc(session, template_id)
def show_templates(self)
-
Print table with templates identifiers and addresses
Expand source code
def show_templates(self): """Print table with templates identifiers and addresses """ doc_table = CliDesigner.get_table("ID", "URI TEMPLATE") with Live(doc_table, refresh_per_second=6): for template_id in self.templates: doc_table.add_row( f"{CliDesigner.random_color()}{template_id}", f"{CliDesigner.random_color()}{self.get_template(template_id=template_id).path}" ) sleep(.321)
class HandlersSearchError (*args)
-
Handlers Search Error
Unpack args and call parent method
Expand source code
class HandlersSearchError(HandlersError): """Handlers Search Error """ def __init__(self, *args): """Unpack args and call parent method """ super().__init__(*args) self.output_format = args[0] self.formats = args[1] def __str__(self): """Str method Returns ------- str String representation """ return f"Can't find handler for format: {self.output_format}. Choose one of: {self.formats}"
Ancestors
- moex.exceptions.HandlersError
- builtins.Exception
- builtins.BaseException
class TemplateRenderError (*args)
-
Template Render Error
Unpack args and call parent method
Expand source code
class TemplateRenderError(TemplatesRepositoryError): """Template Render Error """ def __init__(self, *args): """Unpack args and call parent method """ super().__init__(*args) self.diff = args[0] self.path = args[1] def __str__(self): """Str method Returns ------- str String representation """ return f"You forget set up params: {self.diff} for template: {self.path}"
Ancestors
- moex.exceptions.TemplatesRepositoryError
- builtins.Exception
- builtins.BaseException
class TemplateSearchError (*args)
-
Template Search Error
Unpack args and call parent method
Expand source code
class TemplateSearchError(TemplatesRepositoryError): """Template Search Error """ def __init__(self, *args): """Unpack args and call parent method """ super().__init__(*args) self.template_id = args[0] def __str__(self): """Str method Returns ------- str String representation """ return f"Can't find template with id: {self.template_id}"
Ancestors
- moex.exceptions.TemplatesRepositoryError
- builtins.Exception
- builtins.BaseException