예제 #1
0
def guess(update, context):
    quest = propose_image_to_guess(update.effective_user.id)
    if not quest:
        return context.bot.send_message(
            chat_id=update.effective_chat.id,
            text=f"Sorry, no images for you to guess",
            reply_markup=config.keyboard.action)

    qid, _, img_code, association, user_name = quest
    tile_ids, gt = image.from_repr(img_code)
    imset_name = f"{len(gt)}/{len(tile_ids)}"
    imset = get_imset(imset_name)
    if imset.shape[0] * imset.shape[1] != len(tile_ids):
        return context.bot.send_message(chat_id=update.effective_chat.id,
                                        text=f"Something went wrong",
                                        reply_markup=config.keyboard.action)

    fname = image.guess_imagename(tile_ids)
    if not pathexists(fname):
        fname = image.generate_image(tile_ids, imset.shape)
    context.chat_data['guess'] = {
        'qid': qid,
        'tile_ids': img_code,
        'gt': gt,
        'guess': []
    }

    caption = f"{user_name} says “{association} {len(gt)}”"
    keyboard = config.keyboard.get(imset_name, config.keyboard.empty)
    context.bot.send_photo(chat_id=update.effective_chat.id,
                           photo=open(fname, 'rb'),
                           caption=caption,
                           reply_markup=keyboard)
def photo(update, context):

    context.bot.send_message(chat_id=update.effective_message.chat_id,
                             text=config.caption)
    photo_bytes = update.message.photo[-1].get_file().download_as_bytearray()

    msg = context.bot.send_photo(chat_id=update.effective_message.chat_id,
                                 photo=image.generate_image(photo_bytes))
예제 #3
0
def tweet(interactive=False):
    structure = get_structure()
    status = 'you are {}'.format(' '.join((unicode(s) for s in structure)))
    if interactive:
        print status
        if not raw_input('do u wanna post?\n').startswith('y'):
            return

    image = generate_image([segment.context() for segment in structure])
    api.update_with_media(image, status=status)
def sticker(update, context):

    if (not update.message.sticker.is_animated):
        context.bot.send_message(chat_id=update.effective_message.chat_id,
                                 text=config.caption)
        sticker_bytes = update.message.sticker.get_file(
        ).download_as_bytearray()

        msg = context.bot.send_photo(chat_id=update.effective_message.chat_id,
                                     photo=image.generate_image(sticker_bytes))
예제 #5
0
def make(update, context):
    imset = get_imset(" ".join(context.args))
    tile_ids, selected = image.random_tiling(imset.shape, imset.nos)
    fname = image.generate_image(tile_ids, imset.shape, selected)
    context.chat_data['make'] = {
        'img_code': image.repr_tile_ids_selected(tile_ids, selected)
    }
    context.bot.send_photo(
        chat_id=update.effective_chat.id,
        photo=open(fname, 'rb'),
        caption="Input one word associated with the green cards")
예제 #6
0
def image_holder():
    if request.method == 'POST':
        if not request.is_json:
            return 'Not json fomat'

        request_json = request.get_json()
        if not request_json:
            return 'Get json data failed'

        image_type = request_json['image_type']
        height = request_json['height']
        width = request_json['width']
        color = request_json['color']
        image_path = generate_image(static_dir, image_type, width, height,
                                    color)
        print('image_path:' + image_path)
        image_url = image_path.replace(static_dir, server_url)
        print('image_url:' + image_url)
        return {'image_url': image_url}
    else:
        return 'Unsupport method'
예제 #7
0
 def decode(self, _id, feature, cls, timeslice):
     # TODO: Why is image generation so slow?
     f = feature(_id=_id, persistence=cls)
     img_bytes = generate_image(f[timeslice])
     return DecodeResult(img_bytes, {'Content-Type': 'image/png'})