Exemple #1
0
def search(site, searchterm, number=1, animated=False):
    """Search a cghmc site for a given search string and returns a dictionary including the image & captions."""
    if site == 'frinkiac':
        siteurl = "https://frinkiac.com"
    elif site == 'morbotron':
        siteurl = "https://morbotron.com"
    else:
        print("CGHMC failed. You need to choose Frinkiac or Morbotron as the site")

    searchurl = siteurl + "/api/search?q=" + searchterm
    # Return specific result number (subract one because it's zero-indexed)
    result_number = int(number) - 1
    searchresult = requests.get(searchurl).json()[result_number]

    if animated:
        # Create & send a 2 second GIF
        imageurl = siteurl + "/gif/" + searchresult['Episode'] + "/" + str(searchresult['Timestamp']) + "/" + str(int(searchresult['Timestamp']) + 2000) + ".gif"
        frinkiac_image = image.download(imageurl, '.gif')
    elif not animated:
        imageurl = siteurl + "/meme/" + searchresult['Episode'] + "/" + str(searchresult['Timestamp']) + ".jpg"
        frinkiac_image = image.download(imageurl)

    # Grab the captions and append them to the tuple
    captionurl = siteurl + "/api/caption?e=" + searchresult['Episode'] + "&t=" + str(searchresult['Timestamp'])
    captions = requests.get(captionurl)

    # Create dictionary with results to return
    packed_result = {'image': frinkiac_image, 'captions': captions}

    return packed_result
Exemple #2
0
def run(msg):
    """Return the first image on google for a given search term."""
    if image_search_enabled:
        message = re.match('^(image) (.*)', msg['text'], re.IGNORECASE)
        searchterm = message.group(2)
        print("Image search for: ", searchterm)
        searchurl = "https://www.googleapis.com/customsearch/v1?key=" + key + "&cx=" + engine_id + "&searchType=image&q=" + searchterm
        searchresults = requests.get(searchurl)
        imageurl = searchresults.json()['items'][0]['link']
        print("Downloading & sending image: ", imageurl)
        print('')
        search_image = image.download(imageurl)

        return ({'action': 'send_photo', 'payload': search_image},)
    else:
        return ({'action': 'send_msg', 'payload': "Image search is not enabled."},)
Exemple #3
0
def run(msg):
    """Return a random image when ED is insulted."""
    selfdefense_image = image.download(url)

    return ({'action': 'send_photo', 'payload': selfdefense_image},)
Exemple #4
0
def run(msg):
    """Return a random fuckthisshit image."""
    fuckthis_result = image.download(urls)

    return ({'action': 'send_photo', 'payload': fuckthis_result},)
Exemple #5
0
def run(msg):
    """Return the upyours image."""
    upyours_image = image.download('http://i.imgur.com/am5PDx6.jpg')

    return ({'action': 'send_photo', 'payload': upyours_image},)
Exemple #6
0
def run(msg):
    """Return an image appropriate for a dog danglin afternoon."""
    dogdanglin_image = image.download('http://i.imgur.com/KwVcdsL.png')

    return ({'action': 'send_photo', 'payload': dogdanglin_image},)
Exemple #7
0
def run(msg):
    """Return a scary image when talking about a diet."""
    diet_image = image.download('http://i.imgur.com/kZQDGNn.png')

    return ({'action': 'send_photo', 'payload': diet_image},)
Exemple #8
0
def run(msg):
    """Return wow images."""
    wow_image = image.download(url)

    return ({'action': 'send_photo', 'payload': wow_image},)