Ejemplo n.º 1
0
def showShopStyleResults(chat_id,from_user,context):
    api_json = context['text_query_result']
    result_image_urls = [value['image']['sizes']['IPhone']['url'] for value in api_json['products']]
    
    text_query_result_index = int(context['text_query_result_index'])
    i = 0
    if text_query_result_index+SHOW_THIS_MANY >= len(result_image_urls):
        message = "Well, maybe not. Gosh, you're hard to please :/ Try sending me back a pic of something I've showed you already to keep looking."
        sendSuggestedResponseHowTo(chat_id,from_user,message,context)
        return api_json
    urls=[]
    titles=[]
    for an_image in result_image_urls[text_query_result_index:]:
        if i >= SHOW_THIS_MANY:
            break
        title = api_json['products'][i]['brandedName']
        urls.append(an_image)
        titles.append(title)
        if context['platform'] == 'KIK':
            picture_message = PictureMessage(to=from_user, chat_id=chat_id, pic_url=an_image)
            picture_message.attribution = CustomAttribution(name=title)
            kik.send_messages([picture_message])

        i +=1
    if context['platform'] == 'FB':
        dispatchMessage(context,'image',chat_id,from_user,urls,suggested_responses=titles)
    context['text_query_result_index'] = i + text_query_result_index # remember which results we've showed
    context['text_query_result'] = api_json
    storeContext(chat_id,from_user,context,action='showShopStyleResults')
    if context['platform'] == 'KIK':
        selectAnImageMsg(chat_id,context)
        return api_json
Ejemplo n.º 2
0
def newSearch(chat_id, context):
    from_user = context['from_user']
    dispatchMessage(
        context,
        'text',
        chat_id,
        from_user, [
            "Send me a pic with only the dress you're looking for, OR type in what you're looking for, OR pick \"Anna's Choice\" for a suprise ;)"
        ],
        suggested_responses=["Anna's Choice"])
Ejemplo n.º 3
0
def showFitRoomResults(chat_id, from_user, context):
    """ Sends picture messages through kik using results from Fitroom
    args: chat_id
          from_user
          responseFromAPI:  json from fitroom
    returns:
          responseFromAPI: removed dead image links
    """

    responseFromAPI = context['image_query_result']
    # clean up resuts, lots of duplicates in results....
    result_image_urls = [
        value['imageUrl'] for value in responseFromAPI['images']
    ]

    image_query_result_index = int(context['image_query_result_index'])
    i = 0
    if image_query_result_index + SHOW_THIS_MANY >= len(result_image_urls):
        say(
            chat_id, context,
            "Well, maybe not. Gosh, you're hard to please :/ Try sending me back a pic of something I've showed you already to keep looking."
        )
        return responseFromAPI
    urls = []
    titles = []
    for an_image in result_image_urls[image_query_result_index:]:
        if i >= SHOW_THIS_MANY:
            break
        # some images are blank, they have exactly 5086 or 3084 bytes. This hack
        # skips any images that size. Hacky fix until they fix it on the backend.
        is_blank = requests.head(an_image,
                                 headers={'Accept-Encoding': 'identity'})
        if is_blank.status_code != 200 or is_blank.headers[
                'content-length'] in ('5086', '3084'):
            responseFromAPI['images'].pop(i)
            continue

        urls.append(an_image)
        titles.append(responseFromAPI['images'][i]['title'])
        print an_image, responseFromAPI['images'][i]['pageUrl']
        i += 1
    dispatchMessage(context,
                    'image',
                    chat_id,
                    from_user,
                    urls,
                    suggested_responses=titles)

    context[
        'image_query_result_index'] = i + image_query_result_index  # remember which results we've showed
    context['image_query_result'] = responseFromAPI
    storeContext(chat_id, from_user, context, action='showFitroomResults')
    if context['platform'] == 'KIK':
        selectAnImageMsg(chat_id, context)
        return responseFromAPI
Ejemplo n.º 4
0
def searchOrbuy(chat_id,context):
    """
    User has selected a picture she likes;
    Present the user with the option to visit the store webpage or search again using the selected picture
    """
    from_user = context['from_user']
    if context['platform'] == 'FB':
        buyThis(chat_id,context)
    else:
        suggested_responses = ['Go to store','Search with this pic','See more results']
        dispatchMessage(context,'text',chat_id,from_user,[canned_responses.like_it()],suggested_responses=suggested_responses)
Ejemplo n.º 5
0
def sendWelcomeMessage(chat_id,context):
    """
    These messages are sent once when a user first contacts Anna; they're only
    ever sent once
    """
    from_user = context['from_user']
    msgs = ["Hey, I'm Anna FashionBot and I'm your personal stylist bot!",
            "I can help you find new dresses. Let's get started!",
            "Send a pic of a woman's dress you want to find or just describe it.",
            "Let me show you :)"
            ]
    suggested_responses = ['Show me now!']
    dispatchMessage(context,'text',chat_id,from_user,msgs,suggested_responses=suggested_responses)
Ejemplo n.º 6
0
def showExample(chat_id,context):
    """Anna's choice
    """
    from_user = context['from_user']
    examples = ['https://67.media.tumblr.com/1ac999c8b7993df3a1d933f1f26ed9aa/tumblr_o9mckr1dNV1ra7lgpo1_500.jpg',
                'https://66.media.tumblr.com/8d49c01c751ad772082497cd1a81fe77/tumblr_o9mbu5xJGu1ugb53eo1_1280.jpg',
                'https://66.media.tumblr.com/64fbda3655c3788b30144ed84df56af1/tumblr_o9mfsoQ2gD1tjge28o1_1280.jpg',
                'https://67.media.tumblr.com/da191961868fb3f521263aee6a70daca/tumblr_nzc6fbNNub1sh1xn8o1_400.jpg',
                'http://66.media.tumblr.com/346111ed3cad276b1a3f5630a173a8fe/tumblr_o5znu2zfj91r5wynfo1_500.jpg',
                'https://65.media.tumblr.com/dc403c140ce960644f55039ac63b8228/tumblr_o996wwm4RX1qc04t7o1_500.jpg']
    example_img =  random.choice(examples)
    context['user_img_url'] = example_img
    context['search_type'] = 'image'
    dispatchMessage(context,'image',chat_id,from_user,[example_img],suggested_responses=['Example pic'])
    dispatchMessage(context,'text',chat_id,from_user,["Let's start with something like this ^^"])
    getFitroomResults(chat_id,context)
Ejemplo n.º 7
0
def searchOrbuy(chat_id, context):
    """
    User has selected a picture she likes;
    Present the user with the option to visit the store webpage or search again using the selected picture
    """
    from_user = context['from_user']
    if context['platform'] == 'FB':
        buyThis(chat_id, context)
    else:
        suggested_responses = [
            'Go to store', 'Search with this pic', 'See more results'
        ]
        dispatchMessage(context,
                        'text',
                        chat_id,
                        from_user, [canned_responses.like_it()],
                        suggested_responses=suggested_responses)
Ejemplo n.º 8
0
def showFitRoomResults(chat_id,from_user,context):
    """ Sends picture messages through kik using results from Fitroom
    args: chat_id
          from_user
          responseFromAPI:  json from fitroom
    returns:
          responseFromAPI: removed dead image links
    """

    responseFromAPI = context['image_query_result'] 
        # clean up resuts, lots of duplicates in results....
    result_image_urls = [value['imageUrl'] for value in responseFromAPI['images']]

    
    image_query_result_index = int(context['image_query_result_index'])
    i=0
    if image_query_result_index+SHOW_THIS_MANY >= len(result_image_urls):
        say(chat_id,context,"Well, maybe not. Gosh, you're hard to please :/ Try sending me back a pic of something I've showed you already to keep looking.")
        return responseFromAPI
    urls=[]
    titles=[]
    for an_image in result_image_urls[image_query_result_index:]:
        if i >= SHOW_THIS_MANY:
            break
        # some images are blank, they have exactly 5086 or 3084 bytes. This hack
        # skips any images that size. Hacky fix until they fix it on the backend.
        is_blank =requests.head(an_image, headers={'Accept-Encoding': 'identity'})
        if is_blank.status_code != 200 or is_blank.headers['content-length'] in ('5086', '3084'):
            responseFromAPI['images'].pop(i)
            continue
        
        urls.append(an_image)
        titles.append(responseFromAPI['images'][i]['title'])
        print an_image, responseFromAPI['images'][i]['pageUrl']
        i +=1
    dispatchMessage(context,'image',chat_id,from_user,urls,suggested_responses=titles)
    
    context['image_query_result_index'] = i + image_query_result_index # remember which results we've showed
    context['image_query_result'] = responseFromAPI
    storeContext(chat_id,from_user,context,action='showFitroomResults')
    if context['platform'] == 'KIK':
        selectAnImageMsg(chat_id,context)
        return responseFromAPI
Ejemplo n.º 9
0
def showShopStyleResults(chat_id, from_user, context):
    api_json = context['text_query_result']
    result_image_urls = [
        value['image']['sizes']['IPhone']['url']
        for value in api_json['products']
    ]

    text_query_result_index = int(context['text_query_result_index'])
    i = 0
    if text_query_result_index + SHOW_THIS_MANY >= len(result_image_urls):
        message = "Well, maybe not. Gosh, you're hard to please :/ Try sending me back a pic of something I've showed you already to keep looking."
        sendSuggestedResponseHowTo(chat_id, from_user, message, context)
        return api_json
    urls = []
    titles = []
    for an_image in result_image_urls[text_query_result_index:]:
        if i >= SHOW_THIS_MANY:
            break
        title = api_json['products'][i]['brandedName']
        urls.append(an_image)
        titles.append(title)
        if context['platform'] == 'KIK':
            picture_message = PictureMessage(to=from_user,
                                             chat_id=chat_id,
                                             pic_url=an_image)
            picture_message.attribution = CustomAttribution(name=title)
            kik.send_messages([picture_message])

        i += 1
    if context['platform'] == 'FB':
        dispatchMessage(context,
                        'image',
                        chat_id,
                        from_user,
                        urls,
                        suggested_responses=titles)
    context[
        'text_query_result_index'] = i + text_query_result_index  # remember which results we've showed
    context['text_query_result'] = api_json
    storeContext(chat_id, from_user, context, action='showShopStyleResults')
    if context['platform'] == 'KIK':
        selectAnImageMsg(chat_id, context)
        return api_json
Ejemplo n.º 10
0
def sendWelcomeMessage(chat_id, context):
    """
    These messages are sent once when a user first contacts Anna; they're only
    ever sent once
    """
    from_user = context['from_user']
    msgs = [
        "Hey, I'm Anna FashionBot and I'm your personal stylist bot!",
        "I can help you find new dresses. Let's get started!",
        "Send a pic of a woman's dress you want to find or just describe it.",
        "Let me show you :)"
    ]
    suggested_responses = ['Show me now!']
    dispatchMessage(context,
                    'text',
                    chat_id,
                    from_user,
                    msgs,
                    suggested_responses=suggested_responses)
Ejemplo n.º 11
0
def buyThis(chat_id,context):
    """
    User has selected a picture she likes, and would like to visit the
    store webpage
    """
    from_user = context['from_user']
    prev_context = retrieveContext(chat_id,from_user)
    if 'image_query_result' not in prev_context and 'text_query_result' not in prev_context:
        say(chat_id,context,canned_responses.error_message()+'query results issue')
    elif  'selected_outfit' not in prev_context:
        say(chat_id,context,canned_responses.error_message()+'selection issuse')
    else:
        i = int(prev_context['selected_outfit'])-1
        if prev_context['search_type'] == 'image':
            i = int(prev_context['image_query_result_index'])-SHOW_THIS_MANY+i
            link = prev_context['image_query_result']['images'][i]['pageUrl']
            title =  prev_context['image_query_result']['images'][i]['title']
            img_url = prev_context['image_query_result']['images'][i]['imageUrl']
            # using a text message to send fitroom results because Kik breaks out links by putting a trailing "/"
            link_message = TextMessage(to=from_user,chat_id=chat_id,body=link)
#            link_message = LinkMessage(to=from_user,chat_id=chat_id,url=link,title=title)
        elif prev_context['search_type'] == 'text':
            
            i = int(prev_context['text_query_result_index'])-SHOW_THIS_MANY+i
            img_url = prev_context['text_query_result']['products'][i]['image']['sizes']['IPhone']['url']
            link = prev_context['text_query_result']['products'][i]['clickUrl']
            title = prev_context['text_query_result']['products'][i]['brandedName']
            link_message = LinkMessage(to=from_user,chat_id=chat_id,url=link,title=title)
        if context['platform'] == 'KIK':
            here = TextMessage(to=from_user,chat_id=chat_id,body="Here ya go:")
            tip = TextMessage(to=from_user,chat_id=chat_id,body="Remember you can search again anytime by sending me a pic ;)")
            tip.keyboards.append(
                SuggestedResponseKeyboard(
                    responses=[TextResponse('See more results'),
                            TextResponse('Search with this pic'),
                            TextResponse('New search')]
            ))
            kik.send_messages([here,link_message,tip])
        elif context['platform'] == 'FB':
            dispatchMessage(context,'link',chat_id,from_user,[link],suggested_responses=[title],extras=[img_url])
Ejemplo n.º 12
0
def showExample(chat_id, context):
    """Anna's choice
    """
    from_user = context['from_user']
    examples = [
        'https://67.media.tumblr.com/1ac999c8b7993df3a1d933f1f26ed9aa/tumblr_o9mckr1dNV1ra7lgpo1_500.jpg',
        'https://66.media.tumblr.com/8d49c01c751ad772082497cd1a81fe77/tumblr_o9mbu5xJGu1ugb53eo1_1280.jpg',
        'https://66.media.tumblr.com/64fbda3655c3788b30144ed84df56af1/tumblr_o9mfsoQ2gD1tjge28o1_1280.jpg',
        'https://67.media.tumblr.com/da191961868fb3f521263aee6a70daca/tumblr_nzc6fbNNub1sh1xn8o1_400.jpg',
        'http://66.media.tumblr.com/346111ed3cad276b1a3f5630a173a8fe/tumblr_o5znu2zfj91r5wynfo1_500.jpg',
        'https://65.media.tumblr.com/dc403c140ce960644f55039ac63b8228/tumblr_o996wwm4RX1qc04t7o1_500.jpg'
    ]
    example_img = random.choice(examples)
    context['user_img_url'] = example_img
    context['search_type'] = 'image'
    dispatchMessage(context,
                    'image',
                    chat_id,
                    from_user, [example_img],
                    suggested_responses=['Example pic'])
    dispatchMessage(context, 'text', chat_id, from_user,
                    ["Let's start with something like this ^^"])
    getFitroomResults(chat_id, context)
Ejemplo n.º 13
0
def sendHowTo(chat_id,context):
    from_user = context['from_user']
    example_img = 'https://s-media-cache-ak0.pinimg.com/236x/49/d3/bf/49d3bf2bb0d88aa79c5fb7b41195e48c.jpg'

    dispatchMessage(context,'text',chat_id,from_user,['First, find a picture of the dress. Make sure the dress is the only thing in the picture. Like this:'])
    dispatchMessage(context,'image',chat_id,from_user,[example_img],suggested_responses=['example pic'])
    dispatchMessage(context,'text',chat_id,from_user,["Then I'll try to find similar dresses from my virtual racks. Like these:"])

    context['user_img_url'] = example_img
    context['search_type'] = 'image'
    getFitroomResults(chat_id,context)
Ejemplo n.º 14
0
def sendHowTo(chat_id, context):
    from_user = context['from_user']
    example_img = 'https://s-media-cache-ak0.pinimg.com/236x/49/d3/bf/49d3bf2bb0d88aa79c5fb7b41195e48c.jpg'

    dispatchMessage(context, 'text', chat_id, from_user, [
        'First, find a picture of the dress. Make sure the dress is the only thing in the picture. Like this:'
    ])
    dispatchMessage(context,
                    'image',
                    chat_id,
                    from_user, [example_img],
                    suggested_responses=['example pic'])
    dispatchMessage(context, 'text', chat_id, from_user, [
        "Then I'll try to find similar dresses from my virtual racks. Like these:"
    ])

    context['user_img_url'] = example_img
    context['search_type'] = 'image'
    getFitroomResults(chat_id, context)
Ejemplo n.º 15
0
def say(chat_id, context, msg):
    from_user = context['from_user']
    dispatchMessage(context,'text',chat_id,from_user,[msg])
Ejemplo n.º 16
0
def sendSuggestedResponseHowTo(chat_id, from_user, message, context):
    dispatchMessage(context,
                    'text',
                    chat_id,
                    from_user, [message],
                    suggested_responses=['Show me how'])
Ejemplo n.º 17
0
def newSearch(chat_id,context):
    from_user = context['from_user']
    dispatchMessage(context,'text',chat_id,from_user,
                    ["Send me a pic with only the dress you're looking for, OR type in what you're looking for, OR pick \"Anna's Choice\" for a suprise ;)"],
                    suggested_responses=["Anna's Choice"])
Ejemplo n.º 18
0
def sendSuggestedResponseHowTo(chat_id,from_user,message,context):
    dispatchMessage(context,'text',chat_id,from_user,[message],suggested_responses=['Show me how'])
Ejemplo n.º 19
0
def buyThis(chat_id, context):
    """
    User has selected a picture she likes, and would like to visit the
    store webpage
    """
    from_user = context['from_user']
    prev_context = retrieveContext(chat_id, from_user)
    if 'image_query_result' not in prev_context and 'text_query_result' not in prev_context:
        say(chat_id, context,
            canned_responses.error_message() + 'query results issue')
    elif 'selected_outfit' not in prev_context:
        say(chat_id, context,
            canned_responses.error_message() + 'selection issuse')
    else:
        i = int(prev_context['selected_outfit']) - 1
        if prev_context['search_type'] == 'image':
            i = int(
                prev_context['image_query_result_index']) - SHOW_THIS_MANY + i
            link = prev_context['image_query_result']['images'][i]['pageUrl']
            title = prev_context['image_query_result']['images'][i]['title']
            img_url = prev_context['image_query_result']['images'][i][
                'imageUrl']
            # using a text message to send fitroom results because Kik breaks out links by putting a trailing "/"
            link_message = TextMessage(to=from_user,
                                       chat_id=chat_id,
                                       body=link)


#            link_message = LinkMessage(to=from_user,chat_id=chat_id,url=link,title=title)
        elif prev_context['search_type'] == 'text':

            i = int(
                prev_context['text_query_result_index']) - SHOW_THIS_MANY + i
            img_url = prev_context['text_query_result']['products'][i][
                'image']['sizes']['IPhone']['url']
            link = prev_context['text_query_result']['products'][i]['clickUrl']
            title = prev_context['text_query_result']['products'][i][
                'brandedName']
            link_message = LinkMessage(to=from_user,
                                       chat_id=chat_id,
                                       url=link,
                                       title=title)
        if context['platform'] == 'KIK':
            here = TextMessage(to=from_user,
                               chat_id=chat_id,
                               body="Here ya go:")
            tip = TextMessage(
                to=from_user,
                chat_id=chat_id,
                body=
                "Remember you can search again anytime by sending me a pic ;)")
            tip.keyboards.append(
                SuggestedResponseKeyboard(responses=[
                    TextResponse('See more results'),
                    TextResponse('Search with this pic'),
                    TextResponse('New search')
                ]))
            kik.send_messages([here, link_message, tip])
        elif context['platform'] == 'FB':
            dispatchMessage(context,
                            'link',
                            chat_id,
                            from_user, [link],
                            suggested_responses=[title],
                            extras=[img_url])
Ejemplo n.º 20
0
def say(chat_id, context, msg):
    from_user = context['from_user']
    dispatchMessage(context, 'text', chat_id, from_user, [msg])