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()
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()
def main(mode=PLAIN_MODE, run_once=False): """ A method that watches files for changes and runs the full pipline. """ config = Configuration() setup_logging(config) setup_celery(config) logger.info('Welcome to Specio!') # Start the app as a worker if mode == WORKER_MODE: app.worker_main() # Watch for file changes elif mode == WATCH_MODE: event_handler = get_event_handler(config) observer = get_observer(config, event_handler) logger.info( 'In this mode, Specio will watch {config.path} for changes invoke the ' 'pipeline each time a ".yml" file changes.' ) observer.start() logger.info('Entering runloop. Watching for changes...') try: while True: time.sleep(1) # noqa except KeyboardInterrupt: logger.info('Runloop cancelled by user. Exiting.') observer.stop() observer.join() # Just sit and wait elif mode == IDLE_MODE: try: while True: time.sleep(1) # noqa except KeyboardInterrupt: logger.info('Runloop cancelled by user. Exiting.') # Manual run once elif run_once: logger.info( 'In this mode, Specio will not watch for file changes and must instead ' 'be invoked each time you want to re-run the pipline.' ) configdict = config.as_dict() logger.info(f'Dispatching pipeline for {config.input}') result = pipeline(configdict, config.input) logger.debug(f'Waiting for pipeline to complete...') result.get() logger.info('Pipeline complete! Exiting.') # No valid run mode specified. Skipping. else: pass
def get_event_handler(config): return SpecioEventHandler( config.as_dict(), patterns=config.patterns, ignore_patterns=config.ignore_patterns, ignore_directories=config.ignore_directories, case_sensitive=config.case_sensitive, )
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()
def action(self, sect): action = config.get(sect, 'action') if not action: logging.error('[action] [%s] no action specified', sect) return None try: func = mmplugin.getaction(action) conf = config.as_dict(sect) conf.setdefault('section', sect) result = func(self, conf) self.update(conf, result) return result except: logging.exception('[%s] <%s.%s> %s', sect, func.__module__, func.__name__, self.data) return None
def do_action(self, sect, conn, event, data, sched=None): if not self.action_active: return True if sched: if not self.isenabled(sched): return False data.update({ 'nick0': self.connection.get_nickname(), 'nick1': self.random_user(self.connection.get_nickname()), }) if not self.isenabled(sect, data): return False action = config.get(sect, 'action') if not action: logging.error('[action] [%s] no action specified', sect) return False handler = ircplugin.getaction(action) with exceptlog(sect, handler, data) as run: conf = config.as_dict(sect) conf.setdefault('section', sect) result = run(self, conf, conn, event, data) if result is None: return False data.update(result) self.send_message(conn, sect, data) chain = config.get(sect, 'chain') chain_sect = ':'.join(('action', chain)) if chain and config.has_section(chain_sect): return self.do_action(chain_sect, conn, event, data, sched) return True
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()