Source code for

# -*- coding: utf-8 -*-
============================================================================ module containing classes and methods common to all types of bots
   This *Bot* inherit from Thread, therefore, they can all run in parallel. They communicate via the SQLite 3 database

   .. warning:: Coding style is CamelCase for classes and lowercase_separated_by_underscores A.K.A snake_case for
      methods and variables.
# Basic python3 libraries
import logging
import platform
from os import makedirs
from threading import Thread, BoundedSemaphore

from social.utils.configuration import CONFIG

# Logger common to all instances of bots
logging.basicConfig(filename='social.log', level=logging.INFO, format=CONFIG["logging"]["format"])

[docs]class BotException(Exception): """Specific exception raised by the Bot class""" pass
[docs]class Bot(Thread): """Common class of all the bot in the trafficker module, inherit from Thread""" def __init__(self, login, password): """ **Constructor of the Bot class** :param login: Login to use for this Bot :param password: Password to use for this Bot :raise TypeError: If the database_directory or database has the wrong type """ # Initialize threading Thread.__init__(self) # Database section if isinstance(CONFIG["database"]["folder"], str) is True: self.database_directory = CONFIG["database"]["folder"] makedirs(self.database_directory, exist_ok=True) else: raise TypeError("First argument database_directory must be str type") if isinstance(CONFIG["database"]["filename"], str) is True: self.database = CONFIG["database"]["filename"] else: raise TypeError("Second argument database must be str type") # Manage database resource self.database_semaphore = BoundedSemaphore(value=5) # Credentials if isinstance(login, str) is True: self.login = login else: raise TypeError("Third argument login must be str type") if isinstance(password, str) is True: self.password = password else: raise TypeError("Third argument password must be str type") # On which machine = platform.node()
[docs] def log(self, log_string): """ Common logging method to all bots :param log_string: Log this string passed in parameter """ if isinstance(log_string, str) is True: else: raise BotException("log_string argument must be string type")