def milestone(team_id=None, channel=None, params=None): Misc.array_pop(params) # original slack event object if not params or len(params) < 2: return send_message( ':red_circle: You must provide the following params: `Server Id` and `jira ID`', channel, team_id) short_id = str(Misc.array_pop(params, 0)) source = str(Misc.array_pop(params, 0)).upper() source_notebook = "icap/gwbot-reporting/TEST-milestones-TEST.ipynb" target_notebook = f"icap/gwbot-reporting/{source}.ipynb" send_message(f":python: creating milestone view for `{source}`", channel, team_id) # need to double check exec_params = [ short_id, f"!papermill ../../{source_notebook} ../../{target_notebook} -p source {source}", {} ] preview_params = [short_id, f"{target_notebook}", {}] Jupyter_Web_Commands.exec(channel=channel, params=exec_params) Jupyter_Web_Commands.preview(channel=channel, params=preview_params)
def slack(team_id=None, channel=None, params=None): target = Misc.array_pop(params, 0) height = Misc.to_int(Misc.array_pop(params, 0)) width = Misc.to_int(Misc.array_pop(params, 0)) scroll_by = Misc.to_int(Misc.array_pop(params, 0)) delay = Misc.to_int(Misc.array_pop(params, 0)) if target is None: target = 'general' if width is None: width = 800 if height is None: height = 1000 if scroll_by is None: scroll_by = 0 if delay is None: delay = 0 target_url = '/messages/{0}'.format(target) slack_message( ":point_right: Taking screenshot of slack channel: `{0}` with height `{1}`, width `{2}`, scroll_by `{3}` and delay `{4}`" .format(target, height, width, scroll_by, delay), [], channel, team_id) payload = { 'target': target_url, 'channel': channel, 'team_id': team_id, 'width': width, 'height': height, 'scroll_by': scroll_by, 'delay': delay } aws_lambda = Lambda('osbot_browser.lambdas.slack_web') aws_lambda.invoke_async(payload)
def screenshot(team_id=None, channel=None, params=None): event = params.pop() # needed due to injection of event param try: if len(params) < 2: return send_message(":red_circle: missing `short id` and `path`. The syntax for this method is `screenshot {short_id} {path}`",channel, team_id) max_screenshot_delay = 15 short_id = params.pop(0) path = params.pop(0).replace('<', '').replace('>', '') # fix extra chars added by Slack width = Misc.to_int(Misc.array_pop(params, 0)) height = Misc.to_int(Misc.array_pop(params, 0)) delay = Misc.to_int(Misc.array_pop(params, 0)) if not width : width = 1200 if not height: height = 800 if not delay : delay = 0 if delay > max_screenshot_delay : delay = max_screenshot_delay send_message(":point_right: taking screenshot of notebook `{0}` in server `{1}` with width `{2}`, (min) height `{3}` and delay `{4}`".format(path,short_id,width,height,delay),channel,team_id) payload = {'short_id': short_id, 'path': path,'width': width,'height': height, 'delay' : delay} png_data = Lambda('osbot_jupyter.lambdas.screenshot').invoke(payload) if len(png_data) == 3: send_message(":red_circle: error taking screenshot :{0} ".format(png_data),channel,team_id) else: send_message(":point_right: got screenshot with size `{0}` (sending it to slack) ".format(len(png_data)),channel,team_id) Lambda('gw_bot.lambdas..png_to_slack').invoke({'png_data': png_data, 'team_id': team_id, 'channel': channel}) except Exception as error: send_message(":red_circle: error in screenshot: {0}".format(error),channel,team_id)
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 test_array_pop(self): array = ['1', 2, '3'] assert Misc.array_pop(array) == '3' assert Misc.array_pop(array) == 2 assert Misc.array_pop(array) == '1' assert Misc.array_pop(array) is None assert Misc.array_pop(None) is None array = ['1', 2, '3'] assert Misc.array_pop(array, 1) == 2 assert Misc.array_pop(array, 1) == '3' assert Misc.array_pop(array, 1) is None assert Misc.array_pop(array, 0) == '1' assert Misc.array_pop(array, 0) is None
def view_exec_file(team_id=None, channel=None, params=None): #event = Misc.array_pop(params) # original slack event object if not params or len(params) < 2: build_id = 'gscs' # for now default to this one #return send_message(':red_circle: You must provide the following params: `Server Id`', channel, team_id) else: build_id = str(Misc.array_pop(params, 0)) notebook = Live_Notebook() if notebook.set_build_from_short_id(build_id) is None: return ':red_circle: Could not find Jupyter server with id `{0}`. Please use `jupyter servers` to see the current list of live servers'.format( build_id) (target_notebook, created) = notebook.get_python_invoke_file() send_message( ":point_right: Today's python execution file in server `{0}` is `{1}`, here is what it looks like:" .format(build_id, target_notebook), channel, team_id) width = 1200 height = 1200 delay = 2 png_data = notebook.screenshot(path=target_notebook, width=width, height=height, delay=delay, apply_ui_fixes=False) return send_png_to_slack(png_data, channel, team_id)
def transition_to(self, action): value_split = action.get('value').split('::') issue_id = Misc.array_pop(value_split, 0) transition_to = Misc.array_pop(value_split, 0) transition_name = Misc.array_pop(value_split, 0) try: self.api_jira.issue_transition_to_id(issue_id, transition_to) self.send_message( ':white_check_mark: Changed `{0}` status to: *{1}*. Here are the new transitions available ' .format(issue_id, transition_name)) self.create_ui_actions_with_transitions(issue_id, transition_name, show_intro=False) except Exception as error: self.send_message( ':red_circle: Error in transition_to: {0}'.format(error))
def files(team_id=None, channel=None, params=None): event = params.pop() # needed due to injection of event param short_id = Misc.array_pop(params,0) target = " ".join(params) if short_id is None: return send_message(":red_circle: missing `short id`. The syntax for this method is `contents {short_id} [{path}]`", channel, team_id) notebook = Live_Notebook(short_id=short_id) text_title, text_body = notebook.files(target) attachments = [{'text':text_body, 'color':'good'}] slack_message(text_title, attachments,channel,team_id)
def _get_graph_data(params,layout=None, headless=True): load_dependencies('syncer,requests,pyppeteer,websocket-client'); from osbot_browser.view_helpers.Am_Charts import Am_Charts am_charts = Am_Charts(headless=headless,layout=layout) graph_name = Misc.array_pop(params,0) if graph_name: graph_data = am_charts.get_graph_data(graph_name) return am_charts, graph_data return am_charts,None
def exec(team_id=None, channel=None, params=None): try: event = Misc.array_pop(params) # original slack event object if not params or len(params) < 2: return send_message( ':red_circle: You must provide the following params: `Server Id` and `code` (to execute)', channel, team_id) short_id = str(Misc.array_pop(params, 0)) code = ' '.join(params).replace('“', '"').replace('”', '"').replace( '‘', "'").replace('’', "'") notebook = Live_Notebook() if notebook.set_build_from_short_id(short_id) is None: return ':red_circle: Could not find Jupyter server with id `{0}`. Please use `jupyter servers` to see the current list of live servers'.format( short_id) (target_notebook, created) = notebook.get_python_invoke_file() if created: send_message( ':point_right: Created temp file for dynamic execution: `{0}`' .format(target_notebook), channel, team_id) send_message( ':point_right: Running code with size `{0}` on server `{1}` (on file `{2}`)' .format(len(code), short_id, target_notebook), channel, team_id) result = notebook.execute_python_in_notebook( target_notebook, code, event) if channel: return send_message( ':point_right: Code executed, here is the output:\n ```{0}```' .format(result), channel, team_id) else: return result except Exception as error: return send_message(':red_circle: Error: {0}'.format(error), channel, team_id)
def render(team_id=None, channel=None, params=None, no_render=False, headless=True): page = Misc.array_pop(params, 0) if page is None: return ':red_circle: you need to provide a map to render, try `cup-of-tea`' maps = Maps(headless, page) maps.load_page(True) return maps.send_screenshot_to_slack('not-used', channel)
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 handle_action(self, event): action = Misc.get_value(Misc.array_pop(event.get('actions'), 0), 'value') try: target = getattr(self, action) except: return self.message_not_supported_action(action) try: return target(event) except Exception as error: return self.message_execution_error(error)
def start(team_id=None, channel=None, params=None): try: server_size = 'large' event = Misc.array_pop(params) user = Misc.get_value(event,'data', {}).get('user') repo_name = Misc.array_pop(params,0) if repo_name is None: repo_name = 'gwbot-jupyter-notebooks' # todo: move to global param value #return ":red_circle: you need to provide an git repo with notebooks, for example try `gs-notebook-gscs`" if '-' not in repo_name and len(repo_name) < 10: repo_name = 'gs-notebook-{0}'.format(repo_name) # todo: move to config value (since this is implementation specific) payload = { 'repo_name': repo_name, "channel" : channel , 'user' : user , 'server_size': server_size} #slack_message(f':point_right: about to start a jupyter notebook with params: {payload} ', [], channel) Lambda('osbot_jupyter.lambdas.start_server').invoke_async(payload) except Exception as error: return f':red_circle: error in Jupyter start command: {error}'
def create_file(team_id=None, channel=None, params=None): event = Misc.array_pop(params) # original slack event object if not params or len(params) < 2: return send_message( ':red_circle: You must provide the following params: `Server Id` and `notebook path`', channel, team_id) build_id = str(Misc.array_pop(params, 0)) file_path = Misc.array_pop(params, 0) file_contents = ' '.join(params) notebook = Live_Notebook() file_type = 'notebook' if '.ipynb' in file_path else 'file' if notebook.set_build_from_short_id(build_id) is None: return ':red_circle: Could not find Jupyter server with id `{0}`. Please use `jupyter servers` to see the current list of live servers'.format( build_id) send_message( ':point_right: Creating `{0}` on server `{1}` at location `{2}` with content of size `{3}`' .format(file_type, build_id, file_path, len(file_contents)), channel, team_id) jupyter_api = notebook.jupyter_api() if file_type == 'notebook': result = jupyter_api.notebook_create(file_path, file_contents) else: result = jupyter_api.file_create(file_path, file_contents) if result.get('status') == 'ok': if file_type == 'notebook': url = "{0}/notebooks/{1}".format(jupyter_api.server, file_path) else: url = "{0}/edit/{1}".format(jupyter_api.server, file_path) return send_message( ':white_check_mark: `{0}` created ok, you can see it here: {1}' .format(file_type, url), channel, team_id) else: return send_message( ':red_circle: Error creating notebook ```{0}```'.format( result.get('data')), channel, team_id)
def handle_action(self, event): self.send_message('aaaa') action = Misc.array_pop(event.get('actions'), 0) action_value = Misc.get_value(action, 'value') try: target = getattr(self, action_value) except: channel = event.get('channel').get('id') team_id = event.get('team').get('id') # temp code (refactor when adding full support for blocks) text = ':point_right: message not recognised: {0}'.format(action) API_Slack_Blocks().set_text(text).send_message(channel, team_id) return self.message_not_supported_action( action) # event.get('original_message')) try: return target(event) except Exception as error: return self.message_execution_error(error)
def swimlanes(team_id=None, channel=None, params=None): (go_js, graph_data) = Go_Js_Views._get_graph_data(params, "swimlanes") nodes = [{ 'key': "Pool1", 'text': "By Risk", 'isGroup': True, 'category': "Pool" }] edges = [] groups = [] colors = ["lightblue", "lightgreen", "lightyellow", "orange"] for key, issue in graph_data.get('nodes').items(): if issue: group = Misc.array_add(groups, issue.get('Rating')) nodes.append({ 'key': key, 'group': group }) #issue.get('Summary') for group in list(set(groups)): nodes.append({ 'key': group, 'text': group, 'isGroup': True, 'group': "Pool1", 'color': Misc.array_pop(colors) }) for edge in graph_data.get('edges'): edges.append({'from': edge[0], 'to': edge[2]}) js_code = 'relayoutLanes()' return go_js.render(nodes, edges, js_code=js_code, width=2400, team_id=team_id, channel=channel)
def render(team_id, channel, params): load_dependencies('syncer,requests,pyppeteer,websocket-client') if params: target = params.pop(0) delay = Misc.to_int(Misc.array_pop(params, 0)) if len(params) == 4: clip = { 'x': int(params[0]), 'y': int(params[1]), 'width': int(params[2]), 'height': int(params[3]) } else: clip = None else: return None slack_message(":point_right: rendering file `{0}`".format(target), [], channel, team_id) return Browser_Lamdba_Helper().setup().render_file(team_id, channel, target, clip=clip, delay=delay)
def screenshot(team_id=None, channel=None, params=None, headless=True): event = Misc.array_pop( params ) # original slack event object (don't think this is needed anymore) if not params or len(params) == 0: return send_message( ':red_circle: You must provide an Server Id. Please use `jupyter servers` to see the current list of live servers', channel, team_id) from osbot_jupyter.api.Live_Notebook import Live_Notebook short_id = Misc.array_pop(params, 0) path = Misc.array_pop(params, 0) width = Misc.to_int(Misc.array_pop(params, 0)) height = Misc.to_int(Misc.array_pop(params, 0)) delay = Misc.to_int(Misc.array_pop(params, 0)) if not path: path = '/' if not width: width = 1200 if not height: height = 500 if delay is None: delay = 1 # add one second delay if no value is provided notebook = Live_Notebook(headless=headless) if notebook.set_build_from_short_id(short_id) is None: return ':red_circle: Could not find Jupyter server with id `{0}`. Please use `jupyter servers` to see the current list of live servers'.format( short_id) send_message( ':point_right: taking screenshot of `{0}` with width `{1}`, (min) height `{2}` and delay `{3}`' .format(path, width, height, delay), channel, team_id) png_data = notebook.screenshot( path=path, width=width, height=height, delay=delay, apply_ui_fixes=False ) # when calling the sceenshot via the web command, don't apply the UI fixes return send_png_to_slack(png_data, channel, team_id)
def preview(team_id=None, channel=None, params=None, headless=True): event = Misc.array_pop(params) # original slack event object if not params or len(params) < 2: return send_message( ':red_circle: You must provide an Server Id and file to process. Please use `jupyter servers` to see the current list of live servers', channel, team_id) short_id = Misc.array_pop(params, 0) path = Misc.array_pop(params, 0) width = Misc.to_int(Misc.array_pop(params, 0, 1200)) height = Misc.to_int(Misc.array_pop(params, 0, 800)) delay = Misc.to_int(Misc.array_pop(params, 0, 0)) if width is None: width = 1200 if height is None: height = 800 if delay is None: delay = 0 notebook = Live_Notebook(headless=headless) if notebook.set_build_from_short_id(short_id) is None: return ':red_circle: Could not find Jupyter server with id `{0}`. Please use `jupyter servers` to see the current list of live servers'.format( short_id) if '?show-code' in path: path = f'nbconvert/html/{path}' else: path = f'nbconvert/html/{path}?download=false&osbot-no-code' send_message( ':point_right: taking screenshot of `{0}` with width `{1}`, (min) height `{2}` and delay `{3}`' .format(path, width, height, delay), channel, team_id) png_data = notebook.screenshot(path=path, width=width, height=height, delay=delay, apply_ui_fixes=True) return send_png_to_slack(png_data, channel, team_id)
def mindmap(team_id=None, channel=None, params=None, root_node_text=None): (go_js, graph_data) = Go_Js_Views._get_graph_data(params, "mindmap", headless=True) go_js.load_page(False) (nodes, edges) = Go_Js_Views._get_nodes_and_edges(graph_data, text_field='Summary') data = {"class": "go.TreeModel", "nodeDataArray": []} width = Misc.to_int(Misc.array_pop(params, 0)) height = Misc.to_int(Misc.array_pop(params, 0)) if width and height: go_js.browser().sync__browser_width(width, height) else: go_js.set_browser_width_based_on_nodes(nodes) nodes_indexed = {} if len(nodes) > 0: for index, node in enumerate(nodes): key = node.get('key') #text = "{1} | {0}".format(key,node.get('text')) # need a better way to trigger this text = node.get('text') nodes_indexed[key] = {'index': index, 'text': text} #root_node_text = "{1} | {0}".format(nodes[0].get('key'), nodes[0].get('text')) # and this if root_node_text is None: root_node_text = nodes[0].get('text') data['nodeDataArray'].append({ "key": 0, "text": root_node_text }) # add root node first for edge in edges: from_key = edge['from'] to_key = edge['to'] from_issue = nodes_indexed.get(from_key) to_issue = nodes_indexed.get(to_key) if from_issue: parent = nodes_indexed.get(edge['from']).get('index') else: parent = from_key if to_issue: key = nodes_indexed.get(edge['to']).get('index') text = nodes_indexed.get(edge['to']).get('text') else: key = to_key text = to_key #item = {"key": key, "parent": parent, "text": text, "brush": Misc.get_random_color()} item = { "key": key, "parent": parent, "text": text, "brush": 'darkseagreen' } data['nodeDataArray'].append(item) go_js.invoke_js("create_graph_from_json", data) js_code = 'layoutAll()' go_js.api_browser.sync__await_for_element('#animationFinished') Dev.pprint(go_js.exec_js(js_code)) return go_js.send_screenshot_to_slack(team_id=team_id, channel=channel)
def stream_arn(self): streams = self.dynamo.dynamo_streams().list_streams(TableName=self.table_name).get('Streams') first_one = Misc.array_pop(streams,0) return Misc.get_value(first_one,'StreamArn')
def timeline(team_id=None, channel=None, params=None, headless=True): load_dependencies('syncer,requests,pyppeteer,websocket-client'); from osbot_browser.view_helpers.Am_Charts import Am_Charts am_charts = Am_Charts(headless=headless) Misc.array_pop(params,0) # remove the graph name (which is not used) width = Misc.to_int(Misc.array_pop(params, 0)) height = Misc.to_int(Misc.array_pop(params, 0)) clip = {'x': 0, 'y': 50, 'width': width, 'height': height-100} #clip = None am_charts.browser().sync__browser_width(width, height) try: data = json.loads(" ".join(params)) am_charts.load_page(True) js_code = """ // Create chart instance var chart = am4core.create("chartdiv", am4charts.XYChart); // Create axes var xAxis = chart.xAxes.push(new am4charts.CategoryAxis()); xAxis.dataFields.category = "x"; xAxis.renderer.grid.template.disabled = true; xAxis.renderer.labels.template.disabled = true; xAxis.tooltip.disabled = true; var yAxis = chart.yAxes.push(new am4charts.ValueAxis()); yAxis.min = 0; yAxis.max = 1.99; yAxis.renderer.grid.template.disabled = true; yAxis.renderer.labels.template.disabled = true; yAxis.renderer.baseGrid.disabled = true; yAxis.tooltip.disabled = true; // Create series var series = chart.series.push(new am4charts.LineSeries()); series.dataFields.categoryX = "x"; series.dataFields.valueY = "y"; series.strokeWidth = 4; series.sequencedInterpolation = true; var bullet = series.bullets.push(new am4charts.CircleBullet()); bullet.setStateOnChildren = true; bullet.states.create("hover"); bullet.circle.radius = 10; bullet.circle.states.create("hover").properties.radius = 15; var labelBullet = series.bullets.push(new am4charts.LabelBullet()); labelBullet.setStateOnChildren = true; labelBullet.states.create("hover").properties.scale = 1.2; labelBullet.label.text = "{text}"; labelBullet.label.maxWidth = 150; labelBullet.label.wrap = true; labelBullet.label.truncate = false; labelBullet.label.textAlign = "middle"; labelBullet.label.paddingTop = 20; labelBullet.label.paddingBottom = 20; labelBullet.label.fill = am4core.color("#999"); labelBullet.label.states.create("hover").properties.fill = am4core.color("#000"); labelBullet.label.propertyFields.verticalCenter = "center"; chart.cursor = new am4charts.XYCursor(); chart.cursor.lineX.disabled = true; chart.cursor.lineY.disabled = true; """ # data = [{"x": "1","y": 1,"text": "[bold]2018 Q1[/]\nAAAA There seems to be some furry animal living in the neighborhood.", "center": "bottom"}, { # "x": "2", # "y": 1, # "text": "[bold]2018 Q2[/]\nWe're now mostly certain it's a fox.", # "center": "top" # }, { # "x": "3", # "y": 1, # "text": "[bold]2018 Q3[/]\nOur dog does not seem to mind the newcomer at all.", # "center": "bottom" # }, { # "x": "4", # "y": 1, # "text": "[bold]2018 Q4[/]\nThe quick brown fox jumps over the lazy dog.", # "center": "top" # }]; am_charts.exec_js(js_code) am_charts.assign_variable_js('window.chart.data', data) return am_charts.send_screenshot_to_slack(team_id, channel,clip=clip) #return "ok {0}".format(data) except Exception as error: return "error: {0}".format(error)
def get_active_build_id(self, project_name=None): builds = self.get_active_builds(project_name=project_name, stop_when_match=True) return Misc.array_pop(list(set(builds)))
def build_info(self, build_id): builds = self.codebuild.batch_get_builds(ids=[build_id]).get('builds') return Misc.array_pop(builds, 0)
def project_info(self): projects = Misc.get_value( self.codebuild.batch_get_projects(names=[self.project_name]), 'projects', []) return Misc.array_pop(projects, 0)
def show(team_id, channel, params, data=None): if len(params) < 1: text = ':red_circle: Hi, for the `show` command, you need to provide an `graph_name`' slack_message(text, [], channel, team_id) return graph_name = Misc.array_pop(params, 0) graph = Lambda_Graph().get_gs_graph___by_name(graph_name) if graph is None: text = ':red_circle: Graph with name `{0}` not found'.format( graph_name) slack_message(text, [], channel, team_id) else: default_engine = 'viva_graph' engines = Misc.array_pop(params, 0) if engines is None: engines = default_engine if engines != default_engine: # only show in case there is more than one engine text = f":point_right: Showing graph with name `{graph_name}`, with `{len(graph.nodes)}` nodes and `{len(graph.edges)}` edges)" slack_message(text, [], channel, team_id) if 'plantuml' in engines: slack_message('...using `plantuml`', [], channel, team_id) Lambda('gw_bot.lambdas.puml_to_slack').invoke_async({ "puml": graph.get_puml(), "channel": channel, "team_id": team_id }) if 'vis_js' in engines: slack_message('...using `vis_js`', [], channel, team_id) params = ['graph', graph_name, 'default'] Lambda('osbot_browser.lambdas.lambda_browser').invoke_async({ "params": params, 'data': { 'team_id': team_id, 'channel': channel } }) if 'viva_graph' in engines: if engines != default_engine: # only show in case there is more than one engine slack_message('...using `viva_graph`', [], channel, team_id) params = ['viva_graph', graph_name, 'default'] Lambda('osbot_browser.lambdas.lambda_browser').invoke_async({ "params": params, 'data': { 'team_id': team_id, 'channel': channel } }) if 'go_js' in engines: slack_message('...using `go_js`', [], channel, team_id) params = ['go_js', graph_name, 'circular'] Lambda('osbot_browser.lambdas.lambda_browser').invoke_async({ "params": params, 'data': { 'team_id': team_id, 'channel': channel } })
def update_notebook(team_id=None, channel=None, params=None): event = Misc.array_pop(params) # original slack event object if not params or len(params) < 2: return send_message( ':red_circle: You must provide the following params: `Server Id` and `notebook path` (to update)', channel, team_id) short_id = str(Misc.array_pop(params, 0)) target_notebook = Misc.array_pop(params, 0) if '.ipynb' not in target_notebook: target_notebook += '.ipynb' notebook = Live_Notebook() if notebook.set_build_from_short_id(short_id) is None: return send_message( ':red_circle: Could not find Jupyter server with id `{0}`. Please use `jupyter servers` to see the current list of live servers' .format(short_id), channel, team_id) if notebook.jupyter_api().contents(target_notebook) is None: return send_message( ":red_circle: Could not find notebook `{0}` in server `{1}`". format(target_notebook, short_id), channel, team_id) send_message( ":point_right: Updating notebook `{0}` on server `{1}`".format( target_notebook, short_id), channel, team_id) target_notebook_fixed = "notebooks/{0}".format(target_notebook) code = '!cd ../../..; jupyter nbconvert --to notebook --inplace --execute {0}'.format( target_notebook_fixed) #note for longer executions the save is not working ok (invoke_notebook, created) = notebook.get_python_invoke_file() send_message( ':point_right: Running code with size `{0}` on server `{1}` (on file `{2}`)' .format(len(code), short_id, invoke_notebook), channel, team_id) result = notebook.execute_python_in_notebook(invoke_notebook, code, event) #send_message("result: ```{0}``` ".format(result),channel, team_id) if result and ('[NbConvertApp] Writing' not in result): #or ('[js eval error]' in result): if 'matched no files' in result: send_message( ":red_circle: Update failed, could not find notebook \n ```{0}```" .format(target_notebook_fixed), channel, team_id) send_message( "Here is the execution code: ```{0}````".format(code), channel, team_id) return else: return send_message( ":red_circle: Update failed: \n ```{0}```".format(result), channel, team_id) send_message(":point_right: Notebook updated ok", channel, team_id) # need to double check params = [short_id, target_notebook, event] return Jupyter_Web_Commands.preview(team_id, channel, params)