Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand All @@ -41,6 +45,7 @@ def load_search_places_file():
exit(1)


# Search depth
SEARCH_DEPTH_DAYS = 60


Expand Down Expand Up @@ -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:
Expand Down
22 changes: 18 additions & 4 deletions mongodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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} !")
Expand All @@ -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":
Expand Down