Example #1
0
def run(event, context):

    channel         = event.get('channel')
    png_data        = event.get('png_data')
    s3_bucket       = event.get('s3_bucket')
    s3_key          = event.get('s3_key')
    title           = event.get('title')
    team_id         = event.get('team_id')
    aws_secrets_id  = event.get('aws_secrets_id')
    if  team_id == 'T7F3AUXGV': aws_secrets_id = 'slack-gs-bot'             # hard coded values
    if  team_id == 'T0SDK1RA8': aws_secrets_id = 'slack-gsbot-for-pbx'      # need to move to special function

    bot_token       = Secrets(aws_secrets_id).value()

    if png_data:
        #(fd, tmp_file) = tempfile.mkstemp('png')
        tmp_file = Files.temp_file('.png')
        with open(tmp_file, "wb") as fh:
            fh.write(base64.decodebytes(png_data.encode()))
    else:
        if s3_bucket and s3_key:
            tmp_file = S3().file_download_and_delete(s3_bucket, s3_key)
        else:
            return None

    return send_file_to_slack(tmp_file, title, bot_token, channel)
 def __init__(self, headless=True, auto_close=True, url_chrome=None):
     self.file_tmp_last_chrome_session = '/tmp/browser-last_chrome_session.json'
     #self.file_tmp_screenshot          = '/tmp/browser-page-screenshot.png'
     self.file_tmp_screenshot = Files.temp_file('.png')
     self._browser = None
     self.headless = headless
     self.auto_close = auto_close  # happens after taking a screenshot
     self.url_chrome = url_chrome
     self.log_js_errors_to_console = True
Example #3
0
 def test_get_set_last_chrome_session(self):
     self.api.file_tmp_last_chrome_session = Files.temp_file()
     data = {
         'chrome_devtools':
         'ws://127.0.0.1:64979/devtools/browser/75fbaab9-33eb-41ee-afd9-4aed65166791'
     }
     self.api.set_last_chrome_session(data)
     assert self.api.get_last_chrome_session() == data
     Files.delete(self.api.file_tmp_last_chrome_session)
Example #4
0
 async def get_screenshot_via_browser(self,
                                      url=None,
                                      png_file=None,
                                      full_page=True,
                                      clip=None,
                                      viewport=None,
                                      js_code=None,
                                      delay=None):
     if clip is not None: full_page = False
     if png_file is None: png_file = Files.temp_file('.png')
     if url is None: url = self.web_server.url()
     await self.api_browser.browser()
     return await self.api_browser.screenshot(url,
                                              full_page=full_page,
                                              file_screenshot=png_file,
                                              clip=clip,
                                              viewport=viewport,
                                              js_code=js_code,
                                              delay=delay)
Example #5
0
 def __init__(self):
     self.url_plantuml_server = 'http://localhost:8080/form'
     self.tmp_png_file = Files.temp_file('.png')
 def send_png_data_to_slack(self, team_id, channel, target, png_data):
     png_file = Files.temp_file('.png')
     with open(png_file, "wb") as fh:
         fh.write(base64.decodebytes(png_data.encode()))
     return self.send_png_file_to_slack(team_id, channel, target, png_file)