Ejemplo n.º 1
0
assert os.path.isfile('.env')                        # environment variables file

# Instantiate logging in accordance with config file
fileConfig('../utils/logging_config.ini')
logger = logging.getLogger('telegram')

# Explicit start of the bot runtime
logger.info("Started Telegram bot")

# message used when the help command is invoked
HELP_MESSAGE="You can find more about this bot [here](https://github.com/bobby-b-bot/telegram/blob/master/README.md)"


try:
    # Check if it is PROD or TEST environment
    environment = get_env('ENV', __file__)
    logger.info("Running on environment: {}".format(environment))

    # Get TOKEN environment variable
    token = get_env('TOKEN', __file__)
    logger.info("Got Telegram token")
except Exception as e:
    logger.exception("Could not get environment variables: {}".format(str(vars(e))))

try:
    # Instantiate Telegram bot
    bot_updater = Updater(token=token)
    bot_dispatcher = bot_updater.dispatcher

    logger.info("Instantiated Telegram client")
except Exception as e:
Ejemplo n.º 2
0
assert os.path.isfile('blocked_users.json')  # blocked users file

if not os.path.isfile(
        'posts_replied_to.txt'):  # If record file does not exist create it
    open("posts_replied_to.txt", "w+")

# Instantiate logging in accordance with config file
fileConfig('../utils/logging_config.ini')
logger = logging.getLogger('reddit')

# Explicit start of the bot runtime
logger.info("Started Reddit bot")

try:
    # Check if it is PROD or TEST environment, which changes the variables such as subreddits
    environment = get_env('ENV', __file__)
    logger.info("Running on environment: {}".format(environment))

    with open('subs.json', 'r') as subs:

        if environment == 'TEST':
            # test sub is in environment variables
            subreddits = get_env('TST_SUBS', __file__)
        elif environment == 'PROD':
            # productive subs are on a JSON file
            json_raw = json.load(subs)
            subreddits = '+'.join(json_raw)
        else:
            raise Exception  # invalid environment variable

    logger.info("Got subreddit names: bot running on {} subreddits".format(