Exemple #1
0
def pycamp_logo(message, title):
    botsend(message, 'Python Boot Camp ロゴ作成中... :hammer:')

    fontfile = Path(__file__).parent / 'fonts' / FONT
    font = ImageFont.truetype(str(fontfile), size=TEXT_SIZE)

    for name, size in IMAGES:
        logofile = Path(__file__).parent / 'pycamp' / name
        logo_image = Image.open(logofile)

        logo_image = logo_image.convert('RGBA')
        logo_image.thumbnail(size)

        width, height = size

        background = Image.new('RGBA', (width, TEXT_HEIGHT), BACKGROUND_COLOR)
        draw = ImageDraw.Draw(background)
        text_width, _ = draw.textsize(title, font=font)
        draw.text(((width - text_width) / 2, 0),
                  title,
                  font=font,
                  fill=(0, 0, 0))

        logo_image.paste(background, (0, height - TEXT_HEIGHT))

        with create_tmp_file() as tmpf:
            logo_image.save(tmpf, 'png')
            message.channel.upload_file(name, tmpf)

    botsend(message, 'ロゴ画像を作成しました')
Exemple #2
0
def apps(message):
    log_message_env(message)
    if sdk.tenant_id:
        message.react(GOOD_RESPONSE)
        output = str(get_appdefs(sdk=sdk, idname=idname))

        # Too large for slack, attach as text message
        with create_tmp_file(content=output.encode('ascii')) as tmpf:
            message.channel.upload_file('Application Definitions.txt', tmpf,
                                        '')

            # output_list = output.split('\n')
        # attachments = []
        # for line in output_list:
        #
        #     attachments.append({
        #                 "text": "```" + line + "```",
        #                 "color": "#FFFFFF",
        #                 "mrkdwn_in": ["text"]
        #             })
        # message.send_webapi('', json.dumps(attachments))
        # message.send("```" + str(showsites(sdk_vars=sdk_vars)) + "```")
    else:
        message.react(BAD_RESPONSE)
        message.send(CGX_API_ERROR_MSG)
Exemple #3
0
def upload(message, url):
    url = url.lstrip('<').rstrip('>')
    fname = os.path.basename(url)
    message.reply('uploading {}'.format(fname))
    if url.startswith('http'):
        with create_tmp_file() as tmpf:
            download_file(url, tmpf)
            message.channel.upload_file(fname, tmpf, 'downloaded from {}'.format(url))
    elif url.startswith('/'):
        message.channel.upload_file(fname, url)
Exemple #4
0
def upload(message, url):
    url = url.lstrip('<').rstrip('>')
    fname = os.path.basename(url)
    message.reply('uploading %s' % fname)
    if url.startswith('http'):
        with create_tmp_file() as tmpf:
            download_file(url, tmpf)
            message.channel.upload_file(fname, tmpf, 'downloaded from %s' % url)
    elif url.startswith('/'):
        message.channel.upload_file(fname, url)
Exemple #5
0
def show_daily_timesheet(message, user, *args):
    daily_attendances = user.daily_attendances.order_by(
        DailyAttendance.started_at.desc()).limit(30)
    if not daily_attendances:
        return message.reply("Sorry but I don't have your daily timesheet.")
    daily_timesheet = render_daily_timesheet(daily_attendances)
    filename = 'daily_timesheet.md'
    with create_tmp_file(bytes(daily_timesheet, 'utf-8')) as path:
        safe_upload_file(message,
                         filename,
                         path,
                         'Here is your daily timesheet.',
                         is_text_file=True)
Exemple #6
0
def upload(message, thing):
    # message.channel.upload_file(slack_filename, local_filename,
    #                             initial_comment='')
    if thing == 'favicon':
        url = 'https://slack.com/favicon.ico'
        message.reply('uploading {}'.format(url))
        with create_tmp_file() as tmpf:
            download_file(url, tmpf)
            message.channel.upload_file(url, tmpf,
                                        'downloaded from {}'.format(url))
    elif thing == 'slack.png':
        message.reply('uploading slack.png')
        cwd = os.path.abspath(os.path.dirname(__file__))
        fname = os.path.join(cwd, '../../tests/functional/slack.png')
        message.channel.upload_file(thing, fname)
Exemple #7
0
def upload(message, thing):
    # message.channel.upload_file(slack_filename, local_filename,
    #                             initial_comment='')
    if thing == 'favicon':
        url = 'https://slack.com/favicon.ico'
        message.reply('uploading {}'.format(url))
        with create_tmp_file() as tmpf:
            download_file(url, tmpf)
            message.channel.upload_file(url, tmpf,
                                        'downloaded from {}'.format(url))
    elif thing == 'slack.png':
        message.reply('uploading slack.png')
        cwd = os.path.abspath(os.path.dirname(__file__))
        fname = os.path.join(cwd, '../../tests/functional/slack.png')
        message.channel.upload_file(thing, fname)
Exemple #8
0
def check_response(message, response):
    """
    Check the length of the response and send as an attachement if
    longer than the user specified MAX_MESSAGE_LENGTH.
    """
    max_message_length = settings.MAX_MESSAGE_LENGTH if hasattr(
        settings, 'MAX_MESSAGE_LENGTH') else 50
    if len(response.split('\n')) > max_message_length:
        fname = re.sub('-+', '-', re.sub('[^\w]', '-', message.body['text']))
        response = response.lstrip('```').rstrip('```')
        with create_tmp_file(content=bytes(response, 'utf-8')) as tmpf:
            message.channel.upload_file(fname, tmpf)
        return "Output of {c} has been uploaded as a file due to length.".format(
            c=message.body['text'])
    else:
        return response
Exemple #9
0
def quicklook(message,
              star_id,
              mission=('Kepler', 'K2', 'TESS'),
              cadence='long'):
    message.react('+1')
    try:
        lc = lk.search_lightcurvefile(
            star_id, mission=mission,
            cadence=cadence).download_all().stitch().remove_nans()

        _, ax = plt.subplots(2, 1, figsize=[10, 10], constrained_layout=True)
        lc.plot(ax=ax[0])
        lc.to_periodogram().plot(ax=ax[1])
        with create_tmp_file() as tmp_file:
            plt.savefig(tmp_file + '.png', bbox_inches='tight')
            message.channel.upload_file(star_id, tmp_file + '.png')
    except:
        message.reply('I could not resolve your query. ')
Exemple #10
0
def plot_lightcurve(message,
                    star_id,
                    mission=('Kepler', 'K2', 'TESS'),
                    cadence=None):
    message.react('+1')

    if cadence is None:
        lc = lk.search_lightcurvefile(
            star_id, mission=mission).download_all().stitch().remove_nans()
    else:
        lc = lk.search_lightcurvefile(
            star_id, mission=mission,
            cadence=cadence).download_all().stitch().remove_nans()

    _, ax = plt.subplots(figsize=[10, 5], constrained_layout=True)
    lc.plot(ax=ax)
    with create_tmp_file() as tmp_file:
        plt.savefig(tmp_file + '.png', bbox_inches='tight')
        message.channel.upload_file(star_id, tmp_file + '.png')
Exemple #11
0
def show_alarms(message, code_list):
    log_message_env(message)
    if sdk.tenant_id:
        # get alarms
        message.react(GOOD_RESPONSE)
        if code_list == "all":
            ec = []
            message.reply("Retrieving all alarms")
            output = (getevents.run(sdk, ec, 10, global_id2n))

            # Too large for slack, attach as text message
            with create_tmp_file(content=output.encode('ascii')) as tmpf:
                message.channel.upload_file('Alarms.csv', tmpf, '')

        else:
            message.reply("This is the code_list: ({0}).".format(code_list))
    else:
        message.react(BAD_RESPONSE)
        message.reply(CGX_API_ERROR_MSG)