Example #1
0
    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))

        if target is None: target = 'general'
        if width  is None: width = 800
        if height is None: height = 1000

        target_url = '/messages/{0}'.format(target)

        slack_message(":point_right: taking screenshot of slack channel: `{0}` with height `{1}` and width `{2}`".format(target, height,width), [], channel, team_id)

        payload = {'target' : target_url,
                   'channel': channel,
                   'team_id': team_id,
                   'width'  : width,
                   'height' : height}
        aws_lambda      = Lambda('osbot_browser.lambdas.slack_web')
        png_data        = aws_lambda.invoke(payload)

        browser_helper  = Browser_Lamdba_Helper()
        return browser_helper.send_png_data_to_slack(team_id, channel, target, png_data)
    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()}
                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)
Example #3
0
 def screenshot(team_id=None, channel=None, params=[]):
     url          = params.pop(0).replace('<', '').replace('>', '')  # fix extra chars added by Slack
     delay        = Misc.to_int(Misc.array_pop(params,0))
     slack_message(":point_right: taking screenshot of url: {0}".format(url),[], channel,team_id)
     browser_helper = Browser_Lamdba_Helper().setup()
     png_data       = browser_helper.get_screenshot_png(url,full_page=True, delay=delay)
     return browser_helper.send_png_data_to_slack(team_id,channel,url, png_data)
    def _get_graph_data(params, layout=None, headless=True):
        load_dependencies(['syncer', 'requests'])
        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
Example #5
0
    def render(team_id, channel, params):

        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)
Example #6
0
 def message_raw(self):
     messages = self.sqs().receive_message(
         QueueUrl=self.url(), MessageAttributeNames=['All']).get('Messages')
     return Misc.array_pop(messages, 0)
Example #7
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)
Example #8
0
 def build_info(self, build_id):
     builds = self.codebuild.batch_get_builds(ids=[build_id]).get('builds')
     return Misc.array_pop(builds,0)
 def page(*event):
     path = Misc.array_pop(event[2], 0)
     return send_screenshot_to_slack(path, event[1], event[2])
    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=1400, team_id=team_id, channel=channel)
Example #11
0
 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')
Example #12
0
    def timeline(team_id=None, channel=None, params=None, headless=True):
        load_dependencies(['syncer', 'requests'])
        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)