-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from guibacellar/V0.3.0-dev
Integrating version 0.3.0-DEV for release
- Loading branch information
Showing
124 changed files
with
5,730 additions
and
695 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ on: | |
|
||
pull_request: | ||
branches: | ||
- develop | ||
- V*-dev | ||
- main | ||
|
||
paths-ignore: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
"""OSIx Base Module.""" | ||
from __future__ import annotations | ||
|
||
import abc | ||
from configparser import ConfigParser | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Signal Entity Mapper.""" | ||
from __future__ import annotations | ||
|
||
from configparser import SectionProxy | ||
from typing import Optional | ||
|
||
from TEx.models.facade.signal_entity_model import SignalEntity | ||
|
||
|
||
class SignalEntityMapper: | ||
"""Signal Entity Mapper.""" | ||
|
||
@staticmethod | ||
def to_entity(section_proxy: Optional[SectionProxy]) -> SignalEntity: | ||
"""Map the Configuration KEEP_ALIVE to Entity.""" | ||
# Build Model | ||
if section_proxy: | ||
return SignalEntity( | ||
enabled=section_proxy.get('enabled', fallback='false') == 'true', | ||
keep_alive_interval=int(section_proxy.get('keep_alive_interval', fallback='0')), | ||
notifiers={ | ||
'KEEP-ALIVE': section_proxy.get('keep_alive_notifer', fallback='').split(','), | ||
'INITIALIZATION': section_proxy.get('initialization_notifer', fallback='').split(','), | ||
'SHUTDOWN': section_proxy.get('shutdown_notifer', fallback='').split(','), | ||
'NEW-GROUP': section_proxy.get('new_group_notifer', fallback='').split(','), | ||
}, | ||
) | ||
|
||
return SignalEntity( | ||
enabled=False, | ||
keep_alive_interval=300, | ||
notifiers={ | ||
'KEEP-ALIVE': [], | ||
'INITIALIZATION': [], | ||
'SHUTDOWN': [], | ||
'NEW-GROUP': [], | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
"""Telethon Event Entity Mapper.""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Optional, Union | ||
|
||
from pydantic import BaseModel | ||
from telethon.errors import ChannelPrivateError | ||
from telethon.tl.patched import Message | ||
from telethon.tl.types import Channel, Chat, PeerUser, User | ||
|
||
from TEx.models.facade.finder_notification_facade_entity import FinderNotificationMessageEntity | ||
from TEx.models.facade.media_handler_facade_entity import MediaHandlingEntity | ||
|
||
logger = logging.getLogger('TelegramExplorer') | ||
|
||
|
||
class TelethonMessageEntityMapper: | ||
"""Telethon Event Entity Mapper.""" | ||
|
||
class ChatPropsModel(BaseModel): | ||
"""Model for __map_chat_props method.""" | ||
|
||
chat_id: int | ||
chat_title: str | ||
|
||
@staticmethod | ||
async def to_finder_notification_facade_entity(message: Message, downloaded_media_info: Optional[MediaHandlingEntity], ocr_content: Optional[str]) -> \ | ||
Optional[FinderNotificationMessageEntity]: | ||
"""Map Telethon Event to FinderNotificationMessageEntity.""" | ||
if not message: | ||
return None | ||
|
||
try: | ||
mapped_chat_props: TelethonMessageEntityMapper.ChatPropsModel = TelethonMessageEntityMapper.__map_chat_props( | ||
entity=await message.get_chat(), | ||
) | ||
except ChannelPrivateError as _ex: | ||
return None | ||
|
||
raw_text: str = message.raw_text | ||
if ocr_content: | ||
if raw_text and raw_text != '': | ||
raw_text += '\n\n' | ||
|
||
raw_text += ocr_content | ||
|
||
h_result: FinderNotificationMessageEntity = FinderNotificationMessageEntity( | ||
date_time=message.date, | ||
raw_text=raw_text, | ||
group_name=mapped_chat_props.chat_title, | ||
group_id=mapped_chat_props.chat_id, | ||
from_id=message.from_id.user_id if isinstance(message.from_id, PeerUser) else None, | ||
to_id=message.to_id.channel_id if message.to_id is not None and hasattr(message.to_id, 'channel_id') else None, | ||
reply_to_msg_id=message.reply_to.reply_to_msg_id if message.is_reply and message.reply_to else None, | ||
message_id=message.id, | ||
is_reply=message.is_reply, | ||
downloaded_media_info=downloaded_media_info, | ||
found_on='UNDEFINED', | ||
) | ||
|
||
return h_result | ||
|
||
@staticmethod | ||
def __map_chat_props(entity: Union[Channel, User, Chat]) -> TelethonMessageEntityMapper.ChatPropsModel: | ||
"""Map Chat Specific Props.""" | ||
if isinstance(entity, (Channel, Chat)): | ||
return TelethonMessageEntityMapper.ChatPropsModel( | ||
chat_id=entity.id, | ||
chat_title=entity.title if entity.title else '', | ||
) | ||
|
||
if isinstance(entity, User): | ||
return TelethonMessageEntityMapper.ChatPropsModel( | ||
chat_id=entity.id, | ||
chat_title=entity.username if entity.username else (entity.phone if entity.phone else ''), | ||
) | ||
|
||
raise AttributeError(entity, 'Invalid entity type: ' + str(type(entity))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
TEx/core/media_download_handling/do_nothing_media_downloader.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
"""Do Nothing Media Downloader.""" | ||
from __future__ import annotations | ||
|
||
from typing import Dict | ||
|
||
from telethon.tl.types import Message | ||
from telethon.tl.patched import Message | ||
|
||
|
||
class DoNothingMediaDownloader: | ||
"""Do Nothing Media Downloader.""" | ||
|
||
@staticmethod | ||
async def download(message: Message, media_metadata: Dict, data_path: str) -> None: # pylint: disable=W0613 | ||
async def download(message: Message, media_metadata: Dict, data_path: str) -> None: | ||
"""Download the Media, Update MetadaInfo and Return the ID from DB Record. | ||
:param message: | ||
:param media_metadata: | ||
:return: | ||
""" | ||
return None | ||
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.