def test_loads_config_at_file(self): with tempfile.NamedTemporaryFile(mode='w+') as temp: temp.write(self.DUMMY_CONFIG) temp.flush() config = Config(temp.name) self.assertTrue( len(config.get('urls')) > 0, "Expected URLs in config file")
def main(): """Processes command-line arguments, loads the config, launches the flathunter""" parser = argparse.ArgumentParser(description= \ "Searches for flats on Immobilienscout24.de and wg-gesucht.de and sends " + \ "results to Telegram User", epilog="Designed by Nody") parser.add_argument( '--config', '-c', type=argparse.FileType('r', encoding='UTF-8'), default='%s/config.yaml' % os.path.dirname(os.path.abspath(__file__)), help="Config file to use. If not set, try to use '%s/config.yaml' " % os.path.dirname(os.path.abspath(__file__))) args = parser.parse_known_args()[0] # load config config_handle = args.config config = Config(config_handle.name) # check config if not config.urls(): __log__.warning("No urls configured. No crawling will be done.") # adjust log level, if required if config.get('verbose'): __log__.setLevel(logging.DEBUG) __log__.debug("Settings from config: %s", pformat(config)) # start hunting for flats launch_flat_hunt(config)
def main(): # parse args parser = argparse.ArgumentParser( description= "Searches for flats on Immobilienscout24.de and wg-gesucht.de and " "sends results to Telegram User", epilog="Designed by Nody") parser.add_argument( '--config', '-c', type=argparse.FileType('r', encoding='UTF-8'), default='%s/config.yaml' % os.path.dirname(os.path.abspath(__file__)), help="Config file to use. If not set, try to use '%s/config.yaml' " % os.path.dirname(os.path.abspath(__file__))) args = parser.parse_args() # load config config_handle = args.config config = Config(config_handle.name) # check config if not config.get('telegram', dict()).get('bot_token'): __log__.error( "No telegram bot token configured. Starting like this would be meaningless..." ) return if not config.get('telegram', dict()).get('receiver_ids'): __log__.error( "No telegram receivers configured. Starting like this would be meaningless..." ) return if not config.get('urls'): __log__.error( "No urls configured. Starting like this would be meaningless...") return # adjust log level, if required if config.get('verbose'): __log__.setLevel(logging.DEBUG) from pprint import pformat __log__.debug("Settings from config: %s" % pformat(config)) # start hunting for flats launch_flat_hunt(config)
def test_loads_config(self): created = False if not os.path.isfile("config.yaml"): config_file = open("config.yaml", "w") config_file.write(self.DUMMY_CONFIG) config_file.flush() config_file.close() created = True config = Config() self.assertTrue(len(config.get('urls')) > 0, "Expected URLs in config file") if created: os.remove("config.yaml")
def main(): """Processes command-line arguments, loads the config, launches the flathunter""" parser = argparse.ArgumentParser(description= \ "Searches for flats on Immobilienscout24.de and wg-gesucht.de and sends " + \ "results to Telegram User", epilog="Designed by Nody") parser.add_argument( '--config', '-c', type=argparse.FileType('r', encoding='UTF-8'), default='%s/config.yaml' % os.path.dirname(os.path.abspath(__file__)), help="Config file to use. If not set, try to use '%s/config.yaml' " % os.path.dirname(os.path.abspath(__file__))) args = parser.parse_known_args()[0] # load config config_handle = args.config config = Config(config_handle.name) # check config if not config.get('telegram', dict()).get('bot_token'): __log__.error( "No telegram bot token configured. Starting like this would be pointless..." ) return if not config.get('telegram', dict()).get('receiver_ids'): __log__.warning( "No telegram receivers configured - nobody will get notifications." ) # adjust log level, if required if config.get('verbose'): __log__.setLevel(logging.DEBUG) __log__.debug("Settings from config: %s", pformat(config)) # start sending messages telegram_sender = SenderTelegram(config, RedisPubsub(config)) telegram_sender.wait_and_process()
def main(): """Processes command-line arguments, loads the config, launches the flathunter""" parser = argparse.ArgumentParser(description= \ "Searches for flats on Immobilienscout24.de and wg-gesucht.de and sends " + \ "results to Telegram User", epilog="Designed by Nody") parser.add_argument('--config', '-c', type=argparse.FileType('r', encoding='UTF-8'), default='%s/config.yaml' % os.path.dirname(os.path.abspath(__file__)), help="Config file to use. If not set, try to use '%s/config.yaml' " % os.path.dirname(os.path.abspath(__file__)) ) parser.add_argument('--heartbeat', '-hb', action='store', default=None, help='Set the interval time to receive heartbeat messages to check that the bot is' + \ 'alive. Accepted strings are "hour", "day", "week". Defaults to None.' ) args = parser.parse_args() # load config config_handle = args.config config = Config(config_handle.name) # check config notifiers = config.get('notifiers', list()) if 'mattermost' in notifiers \ and not config.get('mattermost', dict()).get('webhook_url'): __log__.error("No mattermost webhook configured. Starting like this would be pointless...") return if 'telegram' in notifiers: if not config.get('telegram', dict()).get('bot_token'): __log__.error("No telegram bot token configured. Starting like this would be pointless...") return if not config.get('telegram', dict()).get('receiver_ids'): __log__.warning("No telegram receivers configured - nobody will get notifications.") if not config.get('urls'): __log__.error("No urls configured. Starting like this would be meaningless...") return # get heartbeat instructions heartbeat_interval = args.heartbeat heartbeat = Heartbeat(config, heartbeat_interval) # adjust log level, if required if config.get('verbose'): __log__.setLevel(logging.DEBUG) __log__.debug("Settings from config: %s", pformat(config)) # start hunting for flats launch_flat_hunt(config, heartbeat)