diff --git a/bot.py b/bot.py index 646ffc5..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 @@ -87,7 +92,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 9f21a07..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,25 +115,29 @@ 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: """ Get data from Search DB collection + Remove "_id" key before return result :return: """ if collection_name == "searchdb":