コード例 #1
0
ファイル: cghmc.py プロジェクト: justingood/terribot
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
コード例 #2
0
ファイル: image.py プロジェクト: justingood/terribot
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."},)
コード例 #3
0
ファイル: selfdefense.py プロジェクト: justingood/terribot
def run(msg):
    """Return a random image when ED is insulted."""
    selfdefense_image = image.download(url)

    return ({'action': 'send_photo', 'payload': selfdefense_image},)
コード例 #4
0
ファイル: fuckthisshit.py プロジェクト: justingood/terribot
def run(msg):
    """Return a random fuckthisshit image."""
    fuckthis_result = image.download(urls)

    return ({'action': 'send_photo', 'payload': fuckthis_result},)
コード例 #5
0
ファイル: upyours.py プロジェクト: justingood/terribot
def run(msg):
    """Return the upyours image."""
    upyours_image = image.download('http://i.imgur.com/am5PDx6.jpg')

    return ({'action': 'send_photo', 'payload': upyours_image},)
コード例 #6
0
ファイル: dogdanglin.py プロジェクト: justingood/terribot
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},)
コード例 #7
0
ファイル: diet.py プロジェクト: justingood/terribot
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},)
コード例 #8
0
ファイル: wow.py プロジェクト: justingood/terribot
def run(msg):
    """Return wow images."""
    wow_image = image.download(url)

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