From 6129147d7ad13cbd6c357ebe1c2832252f0f0cb4 Mon Sep 17 00:00:00 2001 From: CoolCoderCarl <123qwekir2wl@gmail.com> Date: Sun, 29 Jan 2023 15:12:49 +0300 Subject: [PATCH 1/3] Update func comments --- mongodb.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mongodb.py b/mongodb.py index 9f21a07..05311cb 100644 --- a/mongodb.py +++ b/mongodb.py @@ -124,6 +124,7 @@ def is_message_id_exist(self, channel_id: str, message_id: str) -> bool: def get_data_from_db(self, collection_name) -> Dict: """ Get data from Search DB collection + Remove "_id" key before return result :return: """ if collection_name == "searchdb": From 2a541ac3ca78fd89ce5e4d2554f9959a329be189 Mon Sep 17 00:00:00 2001 From: CoolCoderCarl <123qwekir2wl@gmail.com> Date: Fri, 10 Feb 2023 00:24:04 +0300 Subject: [PATCH 2/3] More informative --- bot.py | 2 +- mongodb.py | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/bot.py b/bot.py index 646ffc5..9a1c8ca 100644 --- a/bot.py +++ b/bot.py @@ -87,7 +87,7 @@ def send_message_to_telegram(message: Dict, chat_id: str): ) logging.error(f"Detailed response: {response.text}") except Exception as err: - logging.error(err) + logging.error(f"Err while sending to telegram: {err}") def search_depth_days() -> datetime: diff --git a/mongodb.py b/mongodb.py index 05311cb..6d46668 100644 --- a/mongodb.py +++ b/mongodb.py @@ -74,6 +74,13 @@ def __load_data_from_file(self, search_scheme: str) -> Dict: exit() def insert_data_to_db(self, data_to_insert, database_name: str, collection): + """ + Insert data to any database + :param data_to_insert: + :param database_name: + :param collection: + :return: + """ try: object_id = collection.insert_one(data_to_insert) logging.info( @@ -87,6 +94,9 @@ def insert_data_to_db(self, data_to_insert, database_name: str, collection): # raise Exception def __init__(self): + """ + At start just clean all the records + """ self.__mongo_client.drop_database(self.__SEARCH_DB_NAME) self.__mongo_client.drop_database(self.MESSAGES_IDS_DB) logging.warning(f"Database was purged at start {self.__SEARCH_DB_NAME} !") @@ -105,20 +115,23 @@ def is_db_exist(self) -> bool: logging.warning(f"Database {self.__searchdb} do not exists !") return False - # TODO Need check if work correctly - def is_message_id_exist(self, channel_id: str, message_id: str) -> bool: for object_entry in self.messagesids_collection.find(): try: + # TODO Need check if work correctly if str(message_id) == str(object_entry[str(channel_id)]): + logging.info( + f"The message ID: {message_id} equal to found one: {object_entry[str(channel_id)]}" + ) return True else: + logging.warning(f"There are not found such an ID - {message_id}") return False except KeyError as key_err: - logging.error(key_err) + logging.error(f"Err while checking existing messages {key_err}") return False except BaseException as base_exception: - logging.error(base_exception) + logging.error(f"Err while checking existing messages {base_exception}") return False def get_data_from_db(self, collection_name) -> Dict: From 747ae93ba6e1ccf57bfe05e9d19de2192081aab0 Mon Sep 17 00:00:00 2001 From: CoolCoderCarl <123qwekir2wl@gmail.com> Date: Fri, 10 Feb 2023 00:42:14 +0300 Subject: [PATCH 3/3] More info --- bot.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bot.py b/bot.py index 9a1c8ca..f204772 100644 --- a/bot.py +++ b/bot.py @@ -31,6 +31,10 @@ def load_search_places_file(): + """ + Load file contain places where to search + :return: + """ try: with open(SEARCH_PLACES_LIST, mode="r") as s_p_l: result = [place for place in s_p_l.read().split()] @@ -41,6 +45,7 @@ def load_search_places_file(): exit(1) +# Search depth SEARCH_DEPTH_DAYS = 60