예제 #1
0
def main():
    parser = ArgumentParser(description='Instabot', add_help=False)
    parser.add_argument('--version', action='version', version=__version__)
    choices = [
        func for func in dir(Instabot)
        if callable(getattr(Instabot, func)) and not func.startswith('_')
    ]
    parser.add_argument('action', metavar='|'.join(choices), choices=choices)

    defaults = {
        'config42':
        OrderedDict([
            ('argv', dict(handler=ArgParse, schema=schema, parents=[parser])),
            ('env', {
                'prefix': 'INSTABOT'
            }),
            ('file', {
                'path': 'config.yml'
            }),
        ])
    }

    config = ConfigManager(schema=schema, defaults=defaults)
    config_file = config.get('config.file')
    _config = ConfigManager(schema=schema, path=config_file)
    config.set_many(_config.as_dict())
    config.commit()

    logging.config.dictConfig(config.get("logging"))

    instabot = Instabot(config)
    getattr(instabot, config.get('action'))()
예제 #2
0
def main():
    config = ConfigManager()
    config.set_many(DEFAULT_CONFIG)
    _config = ConfigManager(schema=schema, defaults=defaults)
    config.set_many(_config.as_dict())
    config.set_many(ConfigManager(path=_config.get('config.file')).as_dict())
    config.set_many(_config.as_dict())
    config.commit()

    if config.get('dump_configuration'):
        conf = config.as_dict()
        conf.pop('config42')
        print(yaml.dump(conf))
        exit(0)
    if config.get('show_version'):
        print(instabot_py.__version__)
        exit(0)

    if config.get('verbosity'):
        verbosity = int(config.get('verbosity'))
        if verbosity == 1:
            level = logging.INFO
        elif verbosity > 1:
            level = logging.DEBUG
        config.set("logging.root.level", level)

    logging.config.dictConfig(config.get("logging"))
    bot = InstaBot(config=config)
    bot.mainloop()
예제 #3
0
def main():
    config = ConfigManager()
    config.set_many(DEFAULT_CONFIG)
    _config = ConfigManager(schema=schema, defaults=defaults)
    config.set_many(_config.as_dict())
    config.set_many(
        ConfigManager(schema=schema,
                      path=_config.get('config.file')).as_dict())
    config.set_many(_config.as_dict())
    config.commit()

    if config.get('dump_configuration'):
        conf = config.as_dict()
        conf.pop('config42')
        print(yaml.dump(conf))
        exit(0)
    if config.get('show_version'):
        print("Installed version {}".format(instabot_py.__version__))
        exit(0)

    if not config.get('ignore_updates'):
        last_version = get_last_version()
        if last_version and last_version != instabot_py.__version__:
            print(
                "Newer version available: {}, The current version: {}".format(
                    last_version, instabot_py.__version__))
            print(
                "To update, please type \n python3 -m pip install instabot-py --upgrade --no-cache-dir "
            )
            print("")
            print(
                "  > You can ignore warning, run the instabot with --ignore-updates flag"
            )
            exit(0)

    if config.get('verbosity'):
        verbosity = int(config.get('verbosity'))
        if verbosity == 1:
            level = logging.INFO
        elif verbosity > 1:
            level = logging.DEBUG
        config.set("logging.root.level", level)

    logging.config.dictConfig(config.get("logging"))
    try:
        bot = InstaBot(config=config)
    except CredsMissing:
        print(
            "You didn't provide your Instagram login & password or you didn't specify the configuration file"
        )
        print("Try again :")
        print("")
        print("   instabot-py --login YOUR_LOGIN --password YOUR_PASSWORD")
        print("   instabot-py -c your-config.yml")
        print(
            "You can export and modify the default configuration by typing the command below"
        )
        print("    instabot-py --dump")
        exit(1)
    bot.mainloop()
예제 #4
0
def main():
    config = ConfigManager()
    config.set_many(DEFAULT_CONFIG)
    _config = ConfigManager(schema=schema, defaults=defaults)
    config.set_many(_config.as_dict())
    config_file = _config.get('config.file')
    config.set_many(ConfigManager(schema=schema, path=config_file).as_dict())
    config.set_many(_config.as_dict())
    config.commit()

    configure_logging(config)
    if config.get('dump_configuration'):
        conf = config.as_dict()
        conf.pop('config42')
        conf.pop('dump_configuration')
        print(yaml.dump(conf))
        exit(0)
    if config.get('show_version'):
        print("Installed version {}".format(src.__version__))
        exit(0)

    if not config.get('ignore_updates'):
        last_version = get_last_version()
        if last_version and last_version != src.__version__:
            print("Newer version available: {}, The current version: {}".format(last_version, src.__version__))
            print("To update, please type \n python3 -m pip install instabot-py --upgrade --no-cache-dir ")
            print("")
            print("  > You can ignore warning, run the instabot with --ignore-updates flag")
            exit(0)

    try:
        bot = InstaBot(config=config)
        if config_file:
            bot.logger.info(f"Reading configuration ({len(_config.as_dict())} settings) from {config_file}")
        else:
            bot.logger.info(f"Use the default configuration, add '-c your-config.yml' to specify your config")

    except CredsMissing:
        print("You didn't provide your Instagram login & password or you didn't specify the configuration file")
        print("Try again :")
        print("")
        print("   instabot-py --login YOUR_LOGIN --password YOUR_PASSWORD")
        print("   instabot-py -c your-config.yml")
        print("You can export and modify the default configuration by typing the command below")
        print("    instabot-py --dump")
        exit(1)
    bot.mainloop()
예제 #5
0
def main():
    config = ConfigManager()
    config.set_many(DEFAULT_CONFIG)
    _config = ConfigManager(schema=schema, defaults=defaults)
    config.set_many(_config.as_dict())
    config_file = _config.get('config.file')
    config.set_many(ConfigManager(schema=schema, path=config_file).as_dict())
    config.set_many(_config.as_dict())
    config.commit()

    configure_logging(config)
    if config.get('dump_configuration'):
        conf = config.as_dict()
        conf.pop('config42')
        conf.pop('dump_configuration')
        print(yaml.dump(conf))
        exit(0)

    if config.get('create_configuration'):
        create_configuration()
        exit(0)

    if config.get('show_version'):
        print("Installed version {}".format(instabot_py.__version__))
        exit(0)

    if not config.get('ignore_updates'):
        last_version = get_last_version()
        current_version = instabot_py.__version__
        if last_version and last_version != current_version:
            print(f"""Newer version is available: {last_version}. The current \
version is: {current_version}.
To update instabot-py, please perform: 
    python3 -m pip install instabot-py --upgrade --no-cache-dir
                
    > You can also ignore this warning and upgrade instabot-py later. In this \
case, please run the instabot with '--ignore-updates' flag.""")
            exit(0)

    if config_file:
        print(f"Reading configuration ({len(_config.as_dict())} settings) from"
              f" {config_file}")
    elif os.path.isfile('instabot.config.yml'):
        print("Using 'instabot.config.yml' as a configuration, add "
              "'-c your-config.yml' if you want to use your config file")
    else:
        print("Configuration file has not been found. Please run the instabot "
              "with '--create-config' flag.")
        exit(0)

    try:
        bot = InstaBot(config=config)
    except CredsMissing:
        print(
            """We could not find your Instagram login and/or password. Maybe \
you did not change the default ones in the config file.
You can specify them either directly, correct them in the default config file \
or use your own config file:

    instabot-py --login YOUR_LOGIN --password YOUR_PASSWORD    
or
    instabot-py -c your-config.yml
""")
        exit(1)

    bot.mainloop()
예제 #6
0
import logging.config
import os

from config42 import ConfigManager

from log_analyzer.default_config import DEFAULT_CONFIG

LOGGER = logging.getLogger(__name__)

env_config = ConfigManager(prefix="LOGANALYZER")
logging.basicConfig(
    level=logging.DEBUG if env_config.get("debug") else logging.INFO)
config = ConfigManager(defaults=DEFAULT_CONFIG)
config.set_many(env_config.as_dict())
config_file = config.get("config.file")
config_etcd = config.get("config.etcd")
if config_file:
    if config_file.startswith("/"):
        config_path = config_file
    else:
        cwd = os.getcwd()
        config_path = cwd + "/" + config_file
    config.set_many(
        ConfigManager(path=config_path.replace('//', '/')).as_dict())
    LOGGER.info("Setting configuration from {} : OK".format(config_file))

if config_etcd:
    if not config_etcd.get("keyspace"):
        raise Exception("etcd Keyspace is mandatory")
    try:
        config.set_many(ConfigManager(**config_etcd).as_dict())