def get(self, match: MatchModel): url = ConfigService.get_csgo_server_image_generator_url() params = { "team_won_name": match.team_won.title, "team_lose_name": match.team_lose.title, "championship_name": match.event.title, "team_won_score": match.score_won, "team_lose_score": match.score_lose, "match_type": match.match_kind.title, "team_won_logo_url": ConfigService.get_url_to_cloud_storage( folder=TeamModel.google_storage_folder, image=match.team_won.image ), "team_lose_logo_url": ConfigService.get_url_to_cloud_storage( folder=TeamModel.google_storage_folder, image=match.team_lose.image ), "team_won_flag_url": ConfigService.get_url_to_cloud_storage( folder=CountryModel.google_storage_folder, image=match.get_team_winner_country_image() ), "team_lose_flag_url": ConfigService.get_url_to_cloud_storage( folder=CountryModel.google_storage_folder, image=match.get_team_lose_country_image() ) } full_url = f"{url}?{urlencode(params)}" image = self.screenshot.take_image(full_url) return image
def __init__(self): super(MinioClient, self).__init__() self.client = Minio( os.getenv('MINIO_HOST'), access_key=os.getenv('MINIO_ACCESS_KEY'), secret_key=os.getenv('MINIO_SECRET_KEY'), ) self.config = ConfigService()
def __init__(self): self._config = ConfigService() engine = create_engine( "postgresql+psycopg2://{}:{}@{}/{}".format( self._config.get_db_user(), self._config.get_db_pass(), self._config.get_db_host(), self._config.get_db_table(), pool_pre_ping=True, ), pool_recycle=600, ) Base.metadata.create_all(engine) session = scoped_session( sessionmaker(autocommit=False, autoflush=False, bind=engine)) self._session = session()
def get(self, match: MatchModel) -> str: html = open(ConfigService.get_templates_path() + 'message.html').read() template = Template(html) return template.render( match=match, stars=self.__get_stars(match.stars), hashtags=self.__get_hash_tag_string(match), won_phrase=self.__get_random_won_phrase(), )
class TelegramSender(LoggerAbstract): __config = None def __init__(self): super(TelegramSender, self).__init__() self.__config = ConfigService() def send_image(self, image, caption: str = ''): try: url = f"https://api.telegram.org/bot{self.__config.get_telegram_bot_token()}/sendPhoto" files = { 'photo': image } data = { 'chat_id': self.__config.get_telegram_receiver_id(), 'parse_mode': 'HTML', 'caption': caption } r = requests.post(url, files=files, data=data, timeout=10) except Exception as e: self.logger.error(e, exc_info=True)
class DBSession: _session = None _config: ConfigService def __init__(self): self._config = ConfigService() engine = create_engine( "postgresql+psycopg2://{}:{}@{}/{}".format( self._config.get_db_user(), self._config.get_db_pass(), self._config.get_db_host(), self._config.get_db_table(), pool_pre_ping=True, ), pool_recycle=600, ) Base.metadata.create_all(engine) session = scoped_session( sessionmaker(autocommit=False, autoflush=False, bind=engine)) self._session = session() def add_model(self, model: BaseModel, need_flush: bool = False): self._session.add(model) if need_flush: self.commit() self._session.flush([model]) return model def delete_model(self, model: BaseModel): if model is None: log.warning(f'{__name__}: model is None') try: self._session.delete(model) except IntegrityError as e: log.error(f'`{__name__}` {e}') except DataError as e: log.error(f'`{__name__}` {e}') def query(self, *entities, **kwargs): return self._session.query(*entities, **kwargs) def rollback(self): self._session.rollback() def commit(self, flush: bool = False, need_close: bool = False): try: self._session.commit() except IntegrityError as e: log.error(f'`{__name__}` {e}') raise except DataError as e: log.error(f'`{__name__}` {e}') raise if flush: self._session.flush() if need_close: self.close() def flush(self): self._session.flush() def close_session(self): self._session.close() def close(self): try: self.close() except IntegrityError as e: log.error(f'`{__name__}` {e}') raise except DataError as e: log.error(f'`{__name__}` {e}') raise def __del__(self): self._session.close()
def __init__(self): self.storage_client = MinioClient() self.config = ConfigService() self.http_client_service = HttpClientService()
def __init__(self): super(TelegramSender, self).__init__() self.__config = ConfigService()
def __init__(self): super().__init__() self.http_client_service = HttpClientService() self.config = ConfigService()
def __init__(self): super(Screenshot, self).__init__() self.config = ConfigService()
def __init__(self): self.config = ConfigService() self.screenshot = Screenshot()
def __init__(self): super().__init__() self.repository = CountryRepository() self.image_storage_creator = ImageStorageCreator() self.config = ConfigService()
# coding: utf8 import asyncio import os from dotenv import load_dotenv from src.process.parser_process import ParserProcess from src.process.publisher_process import PublisherProcess from src.service.config_service import ConfigService load_dotenv() PATH = os.path.dirname(os.path.abspath(__file__)) config = ConfigService() task_parser = ParserProcess() task_publisher = PublisherProcess() if __name__ == "__main__": io_loop = asyncio.get_event_loop() tasks = [ io_loop.create_task(task_parser.task(), name="parser"), ] if config.get_app_env() == 'prod': tasks.append(io_loop.create_task(task_publisher.task(), name="publisher")) io_loop.run_until_complete(asyncio.wait(tasks)) io_loop.close()