def main(): if 'DEBUG' in sys.argv: if 'FILE' in sys.argv: logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG, filename='./logs/botlog.log', filemode='w') else: logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG) else: logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO, filename='.logs/botlog.log', filemode='w') configure = SymConfig('./config.json') configure.load_rsa_config() auth = SymBotRSAAuth(configure) auth.authenticate() bot_client = DemoBotClient(auth, configure) datafeed_event_service = bot_client.get_datafeed_event_service() im_ear = IListenToIMs(bot_client) datafeed_event_service.add_im_listener(im_ear) logging.debug('starting datafeed...') datafeed_event_service.start_datafeed()
def main(): print('Python Client runs using RSA authentication') # Configure log configure_logging() # RSA Auth flow: pass path to rsa config.json file configure = SymConfig('../resources/config.json') configure.load_config() auth = SymBotRSAAuth(configure) auth.authenticate() # Initialize SymBotClient with auth and configure objects bot_client = SymBotClient(auth, configure) # Initialize datafeed service datafeed_event_service = bot_client.get_datafeed_event_service() # Initialize listener objects and append them to datafeed_event_service # Datafeed_event_service polls the datafeed and the event listeners # respond to the respective types of events im_listener_test = IMListenerTestImp(bot_client) datafeed_event_service.add_im_listener(im_listener_test) element_listener_test = ElementsListenerTestImp(bot_client) datafeed_event_service.add_elements_listener(element_listener_test) room_listener_test = RoomListenerTestImp(bot_client) datafeed_event_service.add_room_listener(room_listener_test) # Create and read the datafeed print('Starting datafeed') datafeed_event_service.start_datafeed()
def main(): parser = argparse.ArgumentParser() parser.add_argument("--auth", choices=["rsa", "cert"], default="rsa", help="Authentication method to use") parser.add_argument("--config", help="Config json file to be used") args = parser.parse_args() # Configure log configure_logging() # Cert Auth flow: pass path to certificate config.json file if args.config is None: config_path = os.path.join(os.path.dirname(__file__), "..", "resources", "config.json") else: config_path = args.config configure = SymConfig(config_path, config_path) configure.load_config() if args.auth == "rsa": auth = SymBotRSAAuth(configure) elif args.auth == "cert": auth = Auth(configure) else: raise ValueError("Unexpected value for auth: " + args.auth) auth.authenticate() # Initialize SymBotClient with auth and configure objects bot_client = SymBotClient(auth, configure) # Initialize datafeed service datafeed_event_service = bot_client.get_async_datafeed_event_service() # Initialize listener objects and append them to datafeed_event_service # Datafeed_event_service polls the datafeed and the event listeners # respond to the respective types of events im_listener_test = AsyncIMListenerImp(bot_client) datafeed_event_service.add_im_listener(im_listener_test) room_listener_test = AsyncRoomListenerImp(bot_client) datafeed_event_service.add_room_listener(room_listener_test) # This is just a function to demonstrate the non-blocking nature of the async datafeed async def timed_ringer(period_in_seconds, message): while True: await asyncio.sleep(period_in_seconds) print(message) # Create and read the datafeed print('Starting datafeed') loop = asyncio.get_event_loop() awaitables = asyncio.gather(timed_ringer(2, "Ding"), timed_ringer(5, "Dong"), datafeed_event_service.start_datafeed()) loop.run_until_complete(awaitables)
def setUp(self): logging.debug('hi') #RSA Auth flow: configure = SymConfig('sym_api_client_python/resources/rsa_config.json') configure.loadFromRSA() auth = SymBotRSAAuth(configure) auth.authenticate() #initialize SymBotClient with auth and configure objects self.botClient = SymBotClient(auth, configure)
def setUp(self): logging.debug('hi') #RSA Auth flow: configure = SymConfig( 'sym_api_client_python/resources/rsa_config.json') configure.load_rsa_config() auth = SymBotRSAAuth(configure) auth.authenticate() #initialize SymBotClient with auth and configure objects self.botClient = SymBotClient(auth, configure) self.streamId = 'GVYRWwxRnEI7xde31EQz63___prrBEtgdA'
def main(): global loopCount # Configure log configure_logging() # Cert Auth flow: pass path to certificate config.json file config_path = os.path.join(os.path.dirname(__file__), "../resources", "config.json") configure = SymConfig(config_path, config_path) configure.load_config() auth = SymBotRSAAuth(configure) auth.authenticate() # Initialize SymBotClient with auth and configure objects bot_client = SymBotClient(auth, configure) # add rss instance to bot #bot_client.reader = mr stream = 'JjRqq6OBIa7s5wkdNI1b8n___otjgHfIdA' count = 0 while True: logging.debug('XXXX Loop stream ' + stream) count = count + 1 display = "<card accent='tempo-bg-color--blue' iconSrc=''><body><h1>LOOP: " + str( count) + "</h1></body></card>" bot_client.get_message_client().send_msg( stream, dict(message="""<messageML>""" + display + """</messageML>""")) time.sleep(3) display = "<card accent='tempo-bg-color--blue' iconSrc=''><body>" mr = reader.RssReader('../resources/state.json') feeds = mr.checkrss() if len(feeds) == 0: display += "No Feeds" for topic in feeds: for feed in feeds[topic]: logging.debug('adding feeed to show') display += "<p><a href='" + feed['link'] + "'>" + feed[ 'title'] + "</a></p>" display += "</body></card>" print(display) bot_client.get_message_client().send_msg( stream, dict(message="""<messageML>""" + display + """</messageML>"""))
def setUp(self): try: conf, auth = load_from_env_var("SYMPHONY_TEST_CONFIG") self.configure = conf self.auth = auth except ValueError: #RSA Auth flow: self.configure = SymConfig( 'sym_api_client_python/resources/config.json') self.configure.load_config() auth = SymBotRSAAuth(self.configure) auth.authenticate() # Initialize SymBotClient with auth and configure objects self.bot_client = SymBotClient(auth, self.configure)
def setUp(self): try: conf, auth = load_from_env_var("SYMPHONY_TEST_CONFIG") self.configure = conf self.auth = auth except ValueError: #RSA Auth flow: self.configure = SymConfig('sym_api_client_python/resources/config.json') self.configure.load_config() auth = SymBotRSAAuth(self.configure) auth.authenticate() # Initialize SymBotClient with auth and configure objects self.bot_client = SymBotClient(self.auth, self.configure) self.streamId = 'qfC1jCKzQ0ELq96TMs58dX___o_kveOkdA' self.user_id = '349026222344902'
def main(): global loopCount parser = argparse.ArgumentParser() parser.add_argument("--auth", choices=["rsa", "cert"], default="rsa", help="Authentication method to use") parser.add_argument("--config", help="Config json file to be used") args = parser.parse_args() # Configure log configure_logging() configure = SymConfig(_configPath, _configPath) configure.load_config() if args.auth == "rsa": auth = SymBotRSAAuth(configure) elif args.auth == "cert": auth = Auth(configure) else: raise ValueError("Unexpected value for auth: " + args.auth) auth.authenticate() # Initialize SymBotClient with auth and configure objects bot_client = SymBotClient(auth, configure) # Initialize datafeed service datafeed_event_service = bot_client.get_async_datafeed_event_service() # Initialize listener objects and append them to datafeed_event_service # Datafeed_event_service polls the datafeed and the event listeners # respond to the respective types of events im_listener_test = AsyncIMListenerImp(bot_client) datafeed_event_service.add_im_listener(im_listener_test) room_listener_test = AsyncRoomListenerImp(bot_client) datafeed_event_service.add_room_listener(room_listener_test) # Create and read the datafeed logging.debug('Starting datafeed') logging.info('Datafeed started - bot is ready') loop = asyncio.get_event_loop() awaitables = asyncio.gather(datafeed_event_service.start_datafeed()) loop.run_until_complete(awaitables)
def setUp(self): try: conf, auth = load_from_env_var("SYMPHONY_TEST_CONFIG") self.configure = conf self.auth = auth except ValueError: #RSA Auth flow: self.configure = SymConfig('sym_api_client_python/resources/config.json') self.configure.load_config() auth = SymBotRSAAuth(self.configure) auth.authenticate() #initialize SymBotClient with auth and configure objects self.bot_client = SymBotClient(self.auth, self.configure) self.streamId = 'ychiFHXta__zF7YqoLOnN3___pBQNr6mdA' self.messageId = 'g05bspw5c5E7Aq2SMZjIJX___o_KIUG2bQ' self.test_message = dict(message = '<messageML><hash tag="reed"/></messageML>') self.params = {"text" : "hi", "streamId" : "ychiFHXta__zF7YqoLOnN3___pBQNr6mdA"}
def setUp(self): configure = SymConfig( get_path_relative_to_resources_folder('./bot-config.json')) configure.load_config() configure.data['datafeedVersion'] = 'v2' bot_client = SymBotClient(SymBotRSAAuth(configure), configure) self.datafeed_client = bot_client.get_datafeed_client()
def main(): print('Python Client runs using RSA authentication') parser = argparse.ArgumentParser() parser.add_argument("--config", help="Config json file to be used") args = parser.parse_args() # Configure log configure_logging() # Cert Auth flow: pass path to certificate config.json file if args.config is None: config_path = os.path.join(os.path.dirname(__file__), "..", "sym_api_client_python", "resources", "rsa_config.json") else: config_path = args.config # RSA Auth flow: pass path to rsa config.json file) configure = SymConfig(config_path, __file__) configure.load_config() #auth = SymBotRSAAuth(configure) auth = SymBotRSAAuth(configure) auth.authenticate() # Initialize SymBotClient with auth and configure objects bot_client = SymBotClient(auth, configure) # Initialize datafeed service datafeed_event_service = bot_client.get_datafeed_event_service() # Initialize listener objects and append them to datafeed_event_service # Datafeed_event_service polls the datafeed and the event listeners # respond to the respective types of events im_listener_test = IMListenerTestImp(bot_client) datafeed_event_service.add_im_listener(im_listener_test) room_listener_test = RoomListenerTestImp(bot_client) datafeed_event_service.add_room_listener(room_listener_test) # Create and read the datafeed print('Starting datafeed') datafeed_event_service.start_datafeed()
def main(): print('Python Client runs using RSA authentication') # Configure log configure_logging() # RSA Auth flow: pass path to rsa config.json file configure = SymConfig('../resources/config.json') configure.load_config() auth = SymBotRSAAuth(configure) auth.authenticate() # Initialize SymBotClient with auth and configure objects bot_client = SymBotClient(auth, configure) df = DataFeedClient2(bot_client) bot_client.datafeed_client = df # Initialize datafeed service datafeed_event_service = bot_client.get_datafeed_event_service() # Initialize listener objects and append them to datafeed_event_service # Datafeed_event_service polls the datafeed and the event listeners # respond to the respective types of events null_response = mvc.NullResponse() controllers = mvc.Controllers() controllers.add(info.Controller(null_response, info.View())) cc = summary.Controller(null_response, summary.View()) c = tweets.Controller(tweets.Response(bot_client, cc), tweets.View()) controllers.add(c) controllers.add( create.Controller(create.Response(bot_client, c), create.View())) room_listener_test = GeneralRoomListener(bot_client, controllers) datafeed_event_service.add_room_listener(room_listener_test) elements_listener_test = GeneralElementsListener(bot_client, controllers) datafeed_event_service.add_elements_listener(elements_listener_test) # Create and read the datafeed print('Starting datafeed') datafeed_event_service.start_datafeed()
def main(): configure_logging() configure = SymConfig('./config.json') configure.load_config() bot_env = load_env('./environment.json') auth = SymBotRSAAuth(configure) auth.authenticate() # Initialize SymBotClient with auth and configure objects bot_client = SymBotClient(auth, configure) bot_client.bot_id = bot_env['bot_id'] # Initialize datafeed service datafeed_event_service = bot_client.get_datafeed_event_service() # Add Listeners to datafeed event service im_listener_test = IMListenerTestImp(bot_client) datafeed_event_service.add_im_listener(im_listener_test) element_listener_test = ElementsListenerTestImp(bot_client) datafeed_event_service.add_elements_listener(element_listener_test) # Create and read the datafeed print('Starting datafeed') datafeed_event_service.start_datafeed()
def main(): print('hi') #RSA Auth flow: pass path to rsa_config.json file configure = SymConfig('sym_api_client_python/resources/rsa_config.json') configure.loadFromRSA() auth = SymBotRSAAuth(configure) auth.authenticate() #initialize SymBotClient with auth and configure objects botClient = SymBotClient(auth, configure) #initialize datafeed service DataFeedEventService = botClient.getDataFeedEventService() #initialize listener classes and append them to DataFeedEventService class #these listener classes sit in DataFeedEventService class as a way to easily handle events #coming back from the DataFeed imListenerTest = IMListenerTestImp(botClient) DataFeedEventService.addIMListener(imListenerTest) roomListenerTest = RoomListenerTestImp(botClient) DataFeedEventService.addRoomListener(roomListenerTest) #create data feed and read datafeed recursively print('starting datafeed') DataFeedEventService.startDataFeed()
def __init__(self, bot=None, *, threads=None, debug=False, symphony_config="symphony.json", symphony_log="symphony.log", **kwargs): """ Parameters ---------- bot : minette.Minette, default None Instance of Minette. If None, create new instance of Minette by using `**kwargs` symphony_config : str, default 'symphony.json' Config file for Symphony SDK symphony_log : str, defautl 'symphony.log' Log file of Symphony SDK threads : int, default None Max number of worker threads. If None, number of processors on the machine, multiplied by 5 debug : bool, default False Debug mode """ super().__init__(bot=bot, threads=threads, debug=debug, **kwargs) # setup root logger (used internally in symphony libraries) logging.basicConfig( filename=symphony_log, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", filemode="w", level=logging.DEBUG) # set logging level for urllib3 used in symphony libraries logging.getLogger("urllib3").setLevel(logging.WARNING) # configure and authenticate config = SymConfig(symphony_config) config.load_config() auth = SymBotRSAAuth(config) auth.authenticate() # initialize SymBotClient with auth and configure objects self.bot_client = SymBotClient(auth, config) self.datafeed_client = self.bot_client.get_datafeed_client()
def main(): global loopCount # Configure log configure_logging() # Cert Auth flow: pass path to certificate config.json file config_path = os.path.join(os.path.dirname(__file__), "../resources", "config.json") configure = SymConfig(config_path, config_path) configure.load_config() auth = SymBotRSAAuth(configure) auth.authenticate() # Initialize SymBotClient with auth and configure objects bot_client = SymBotClient(auth, configure) # add rss instance to bot mr = reader.RssReader('../resources/state.json') bot_client.reader = mr # Initialize datafeed service datafeed_event_service = bot_client.get_async_datafeed_event_service() # Initialize listener objects and append them to datafeed_event_service # Datafeed_event_service polls the datafeed and the event listeners # respond to the respective types of events im_listener = AsyncIMListenerImp(bot_client) datafeed_event_service.add_im_listener(im_listener) room_listener = AsyncRoomListenerImp(bot_client) datafeed_event_service.add_room_listener(room_listener) # Create and read the datafeed logging.info('Datafeed started - bot is ready') loop = asyncio.get_event_loop() awaitables = asyncio.gather(datafeed_event_service.start_datafeed()) loop.run_until_complete(awaitables)
def main(): # Configure log configure_logging() # Load configuration configure = SymConfig('../resources/config.json') configure.load_config() # Authenticate based on authType in config if ('authType' not in configure.data or configure.data['authType'] == 'rsa'): print('Python Client runs using RSA authentication') auth = SymBotRSAAuth(configure) else: print('Python Client runs using certificate authentication') auth = Auth(configure) auth.authenticate() # Initialize SymBotClient with auth and configure objects bot_client = SymBotClient(auth, configure) # Initialize datafeed service datafeed_event_service = bot_client.get_async_datafeed_event_service() # Initialize listener objects and append them to datafeed_event_service # Datafeed_event_service polls the datafeed and the event listeners # respond to the respective types of events datafeed_event_service.add_im_listener(IMListenerImpl(bot_client)) datafeed_event_service.add_room_listener(RoomListenerImpl(bot_client)) datafeed_event_service.add_elements_listener(ElementsListenerImpl(bot_client)) # Create and read the datafeed print('Starting datafeed') try: loop = asyncio.get_event_loop() loop.run_until_complete(datafeed_event_service.start_datafeed()) except (KeyboardInterrupt, SystemExit): None except: raise
def main(): parser = argparse.ArgumentParser() parser.add_argument("--auth", choices=["rsa", "cert"], default="rsa", help="Authentication method to use") parser.add_argument("--config", help="Config json file to be used") args = parser.parse_args() # Cert Auth flow: pass path to certificate config.json file config_path = args.config configure = SymConfig(config_path, config_path) configure.load_config() if args.auth == "rsa": auth = SymBotRSAAuth(configure) elif args.auth == "cert": auth = Auth(configure) else: raise ValueError("Unexpected value for auth: " + args.auth) auth.authenticate() # Initialize SymBotClient with auth and configure objects bot_client = SymBotClient(auth, configure) print('successfully authenticated') run_import(bot_client) print('successfully imported')
def setUpClass(cls): logging.debug('testing health_check file:') try: conf, auth = load_from_env_var("SYMPHONY_TEST_CONFIG") cls.configure = conf cls.auth = auth except ValueError: #RSA Auth flow: cls.configure = SymConfig( 'sym_api_client_python/resources/config.json') cls.configure.load_config() cls.auth = SymBotRSAAuth(cls.configure) cls.auth.authenticate() # Initialize SymBotClient with auth and configure objects cls.bot_client = SymBotClient(cls.auth, cls.configure)
def setUpClass(cls): logging.debug('testing synchronous datafeed') try: conf, auth = load_from_env_var("SYMPHONY_TEST_CONFIG") cls.configure = conf cls.auth = auth except ValueError: logging.error("Unable to find config from environment variables") #RSA Auth flow: cls.configure = SymConfig( 'sym_api_client_python/resources/config.json') cls.configure.load_config() cls.auth = SymBotRSAAuth(cls.configure) cls.auth.authenticate() # Initialize SymBotClient with auth and configure objects cls.bot_client = SymBotClient(cls.auth, cls.configure)
def step_impl(context): configure = SymConfig('../resources/config.json') configure.load_config() auth = SymBotRSAAuth(configure) auth.authenticate() pass