def default(team_id=None, channel=None, params=None, screenshot=True, no_render=False, headless=True): Browser_Lamdba_Helper().load_browser_dependencies() #load_dependencies('syncer,requests,pyppeteer,websocket-client'); from osbot_browser.view_helpers.VivaGraph_Js import VivaGraph_Js graph_name = params[0] vivagraph_js = VivaGraph_Js(headless=headless) if len(params) > 1: vivagraph_js.browser_width = to_int(params[1], None) if len(params) > 2: vivagraph_js.render_wait = to_int(params[2], None) graph_data = vivagraph_js.get_graph_data(graph_name) if graph_data: (nodes, edges) = vivagraph_js.get_nodes_edges_from_graph_data(graph_data) if no_render is True: return graph_name, nodes, edges, graph_data, vivagraph_js return vivagraph_js.create_graph_and_send_screenshot_to_slack( nodes, edges, graph_name, screenshot, team_id, channel)
def cmd_screenshot(self, params, team_id=None, channel=None): attachments = [] if len(params) < 2: text = ":exclamation: you must provide an issue id " else: params.pop(0) # remove 'issue' command issue_id = params.pop(0).upper() width = to_int(Misc.array_pop(params), None) height = to_int(Misc.array_pop(params), None) delay = to_int(Misc.array_pop(params), None) text = ':point_right: Getting screenshot for issue `{0}`'.format( issue_id) if width: text += ' with width `{0}`'.format(width) if height: text += ' and height `{0}`'.format(height) if delay: text += ' and delay `{0}`'.format(delay) payload = { 'issue_id': issue_id, 'channel': channel, 'team_id': team_id, 'width': width, 'height': height, 'delay': delay } Lambda('osbot_browser.lambdas.jira_web').invoke_async(payload) return {"text": text, "attachments": attachments}
def extract_time(self, output): regex_time_data = '\nreal\t(.*)\nuser\t(.*)\nsys\t(.*)\n' regex_time = '(.*)m(.*)\.(.*)s' match_time_data = search(regex_time_data, output) time_str = '' time_date = '' if match_time_data: time_str = match_time_data.group(1) match_time = search(regex_time, time_str) minutes = to_int(match_time.group(1)) seconds = to_int(match_time.group(2)) micro_seconds = to_int(match_time.group(3)) * 1000 time_date = time(0, minutes, seconds, micro_seconds) #output = remove(output, match_time_data.group(0)) return {"time_str": time_str, 'time_date': time_date}
def __init__(self, app, port="8880", reload=True): self.host = "0.0.0.0" self.log_level = "info" self.port = to_int( port ) # todo: move to globally configurable value (set via Env variables) self.app = app self.reload = reload # automatically reloads server on code changes
def screenshot(team_id=None, channel=None, params=None): params = params or [] try: url = None if len(params) > 0: url = params.pop(0).replace('<', '') \ .replace('>', '') # fix extra chars added by Slack and the u00a0 unicode char. if url == '_': # special mode to not render url = None else: message = ":point_right: taking screenshot of url: {0}".format( url) if url is None: message = ':point_right: no url provided, so showing what is currently on the browser' width = to_int(Misc.array_pop(params, 0)) height = to_int(Misc.array_pop(params, 0)) delay = to_int(Misc.array_pop(params, 0)) if width: message += ", with width `{0}`".format(width) if height: message += ", with height `{0}` (min height)".format(height) if delay: message += ", with delay of `{0}` seconds".format(delay) slack_message(message, [], channel) browser_helper = Browser_Lamdba_Helper().setup() if width: browser_helper.api_browser.sync__browser_width(width, height) png_data = browser_helper.get_screenshot_png(url, full_page=True, delay=delay) slack_message( f':point_right: got screenshot of size {len(png_data)}, sending it to Slack...', [], channel) return browser_helper.send_png_data_to_slack( team_id, channel, url, png_data) except Exception as error: import traceback message = f':red_circle: Browser Error: {error} \n {traceback.format_exc()}' #message = f':red_circle: Browser Error: {error}' return slack_message(message, [], channel, team_id)
def test_to_int(self): assert to_int('12') == 12 assert to_int('aaa') == 0 assert to_int('aaa', 1) == 1
def server_online(self): config = self.config return is_port_open(config.get('server'), to_int(config.get('port')))
def cmd_links(self, params, team_id=None, channel=None, user=None, only_create=False, save_graph=True): if len(params) < 2: text = ':point_right: Hi, here are the valid parameters for the `jira links` command: ' \ '\n\t\t - `jira key` ' \ '\n\t\t - `depth` (default to 1)' \ '\n\t\t - `view engine`: viva_graph (default), or plantuml' \ '\n\t\t - `width` (of graph)' \ '\n\t\t - `delay` (before screenshot)' return {"text": text, "attachments": []} target = array_get(params, 1) depth = to_int(array_get(params, 2), 1) # default to depth 1 view_engine = array_get(params, 3, 'viva_graph') width = to_int(array_get(params, 4), None) delay = to_int(array_get(params, 5), None) if depth > 5: text = f':red_circle: sorry depths bigger than 5 are not supported (since 5 will already give you the only graph)' return {"text": text, "attachments": []} #direction = 'all' # change behaviour to only show all graph = Lambda_Graph().graph_links(target, depth) if graph is None: text = f':red_circle: graph not created for target `{target}`' return {"text": text, "attachments": []} if len(graph.edges) == 0: text = f':red_circle: no graph created from `{target}` (please double check that the issue ID exists)' return {"text": text, "attachments": []} graph_type = f"{target}___depth_{depth}" if save_graph is False: return graph graph_name = graph.render_and_save_to_elk(None, graph_type, channel, user) if only_create: return graph, graph_name, depth, target if channel: message = f':point_right: Created graph with *name* `{graph_name}` *from* `{target}` *depth* `{depth}`' slack_message(message, [], channel) if view_engine == 'plantuml': params = ['show', graph_name, view_engine] Lambda('osbot_jira.lambdas.graph').invoke_async({ "params": params, 'data': { 'team_id': team_id, 'channel': channel } }) else: params = [view_engine, graph_name, 'default', width, delay] Lambda('osbot_browser.lambdas.lambda_browser').invoke_async({ "params": params, 'data': { 'team_id': team_id, 'channel': channel } }) else: return graph, graph_name, depth, target