コード例 #1
0
ファイル: link.py プロジェクト: unspotted/IRCLinkBot
def main(data):
    args = argv('@', data['recv'])
    # look for URL
    link = geturl(data['recv'])
    if link and link != "" and not modeCheck('b', data):
        link = link[0]
        # look for title
        badext = ('.cgi', '.pdf')
        imgext = ('.jpg', '.png', '.gif', '.bmp')
        if not link[-4:].lower() in badext:
            if not link[-4:].lower() in imgext:
                title = gettitle(link)
                if title:
                    title = html_decode(title)
                    # encode unicode object to byte string
                    if type(title) == unicode:
                        title = title.encode('utf-8', "ignore")
                    title = title.replace('\n', ' ')
                    title = title.replace('\r', ' ')
                    title = title.strip()
                    if len(title) >= 150:
                        title = title[:150]
                    if len(link) > int(
                            data['config']['settings']['maxLinkLen']):
                        # post title + tiny
                        data['api'].say(
                            args['channel'],
                            '^ ' + title + ' ' + maketiny(link) + ' ^')
                        return
                    else:
                        # post title only
                        data['api'].say(args['channel'], '^ ' + title + ' ^')
                        return
            else:
                # We've got an image URL.
                from alchemyapi import AlchemyAPI
                alchemyapi = AlchemyAPI()
                response = alchemyapi.imageTagging('url', link)
                if response['status'] == 'OK' and response['imageKeywords'][0][
                        'text'] != 'NO_TAGS':
                    retme = "^ Image of: "
                    for keyword in response['imageKeywords']:
                        retme += "%s(%s%%) " % (
                            keyword['text'], int(
                                float(keyword['score']) * 100))
                    if len(link) > int(
                            data['config']['settings']['maxLinkLen']):
                        retme += maketiny(link) + " "
                    retme += "^"
                    data['api'].say(args['channel'], retme)
                    return
        if len(link) > int(data['config']['settings']['maxLinkLen']):
            # post tiny only
            data['api'].say(args['channel'], '^ ' + maketiny(link) + ' ^')
            return
        else:
            # nothing
            return False
コード例 #2
0
ファイル: pipeline.py プロジェクト: zhewang/salesprediction
def ExtractImageTag(image_url):
    alchemyapi = AlchemyAPI()

    response = alchemyapi.imageTagging('url', image_url)
    results = []

    if response['status'] == 'OK':
        for keyword in response['imageKeywords']:
            results.append(keyword['text'])
            # print(keyword['text'], ' : ', keyword['score'])
        print('')
    else:
        print('Error in image tagging call: ', response['statusInfo'])
コード例 #3
0
ファイル: link.py プロジェクト: Taiiwo/IRCLinkBot
def main(data):
    args = argv('@',data['recv'])
    # look for URL
    link = geturl(data['recv'])
    if link and link != "" and not modeCheck('b', data):
        link = link[0]
        # look for title
        badext = ('.cgi','.pdf')
        imgext = ('.jpg','.png','.gif','.bmp')
        if not link[-4:].lower() in badext:
            if not link[-4:].lower() in imgext:
                title = gettitle(link)
                if title:
                    title = html_decode(title)
                    # encode unicode object to byte string
                    if type(title) == unicode:
                        title = title.encode('utf-8', "ignore")
                    title = title.replace('\n',' ')
                    title = title.replace('\r',' ')
                    title = title.strip()
                    if len(title) >= 150:
                        title = title[:150]
                    if len(link) > int(data['config']['settings']['maxLinkLen']):
                        # post title + tiny
                        data['api'].say(args['channel'], '^ ' + title + ' ' + maketiny(link) + ' ^')
                        return
                    else:
                        # post title only
                        data['api'].say(args['channel'], '^ ' + title + ' ^')
                        return
            else:
                # We've got an image URL.
                from alchemyapi import AlchemyAPI
                alchemyapi = AlchemyAPI()
                response = alchemyapi.imageTagging('url', link)
                if response['status'] == 'OK' and response['imageKeywords'][0]['text'] != 'NO_TAGS':
                    retme = "^ Image of: "
                    for keyword in response['imageKeywords']:
                        retme += "%s(%s%%) " % (keyword['text'], int(float(keyword['score']) * 100))
                    if len(link) > int(data['config']['settings']['maxLinkLen']):
                        retme += maketiny(link) + " "
                    retme += "^"
                    data['api'].say(args['channel'], retme)
                    return
        if len(link) > int(data['config']['settings']['maxLinkLen']):
            # post tiny only
            data['api'].say(args['channel'], '^ ' + maketiny(link) + ' ^')
            return
        else:
            # nothing
            return False
コード例 #4
0
test_text = 'Bob broke my heart, and then made up this silly sentence to test the PHP SDK'
test_html = '<html><head><title>The best SDK Test | AlchemyAPI</title></head><body><h1>Hello World!</h1><p>My favorite language is PHP</p></body></html>'
test_url = 'http://www.nytimes.com/2013/07/13/us/politics/a-day-of-friction-notable-even-for-a-fractious-congress.html?_r=0'
test_jpg = 'pigeon.jpg'


# Create the AlchemyAPI Object
alchemyapi = AlchemyAPI()

print('############################################')
print('#   Image Extraction Example               #')
print('############################################')
print('Processing url: ', image_url)

#### IMAGE TAGGING
response = alchemyapi.imageTagging('url', image_url)
if response['status'] == 'OK':
    print('## Keywords ##')
    for keyword in response['imageKeywords']:
        print(keyword['text'], ' : ', keyword['score'])
    print('')
else:
    print('Error in image tagging call: ', response['statusInfo'])
    
# Sentiment
print('Checking sentiment . . . ')
# response = alchemyapi.sentiment('text', test_text)
response = alchemyapi.sentiment('url', test_url)
if response['status'] == 'OK': 
# 	print(json.dumps(response))
    print(response['docSentiment']['type'])
コード例 #5
0
ファイル: tests.py プロジェクト: hjorthjort/Presens
# Microformats
print('Checking microformats . . . ')
response = alchemyapi.microformats('text', test_text)
assert(response['status'] == 'ERROR')  # only works for html and url content
response = alchemyapi.microformats('html', test_html, {'url': 'test'})
assert(response['status'] == 'OK')
response = alchemyapi.microformats('url', test_url)
assert(response['status'] == 'OK')
print('Microformat tests complete!')
print('')
print('')

# imagetagging
print('Checking imagetagging . . . ')
response = alchemyapi.imageTagging('text', test_text)
assert(response['status'] == 'ERROR')
response = alchemyapi.imageTagging('html', test_html)
assert(response['status'] == 'ERROR')
response = alchemyapi.imageTagging('url', test_url)
assert(response['status'] == 'OK')
response = alchemyapi.imageTagging('image', test_jpg)
assert(response['status'] == 'OK')
print('Image tagging tests complete!')
print('')
print('')

# combined
print('Checking combined . . . ')
response = alchemyapi.combined('text', test_text)
assert(response['status'] == 'OK')
コード例 #6
0
ファイル: firsttest.py プロジェクト: habdulkafi/TwittMapHP
#!/usr/bin/env python

# from __future__ import print_function
from alchemyapi import AlchemyAPI
import json

alchemyapi = AlchemyAPI()


two_people = "C:/Users/husam/Downloads/11430249_10206846582226070_4444383423738402524_n.jpg"

samljack = "C:/Users/husam/Downloads/aKq4MXO_700b_v1.jpg"


# Returns a bounding box for the faces in the picture
# response = alchemyapi.faceTagging('image', two_people)
# response = alchemyapi.faceTagging('image', samljack)


# response = alchemyapi.imageTagging('image', two_people)
response = alchemyapi.imageTagging('image', samljack)



print response



コード例 #7
0
ファイル: trying_api.py プロジェクト: metador/alchemy
print('')


print('')
print('')
print('')
print('############################################')
print('#   Image tagging Example                  #')
print('############################################')
print('')
print('')

print('Processing url: ', image_url)
print('')

response = alchemyapi.imageTagging('url', image_url)

if response['status'] == 'OK':
    print('## Response Object ##')
    print(json.dumps(response, indent=4))

    print('')
    print('## Keywords ##')
    for keyword in response['imageKeywords']:
        print(keyword['text'], ' : ', keyword['score'])
    print('')
else:
    print('Error in image tagging call: ', response['statusInfo'])

print('')
print('')
コード例 #8
0
print("")


print("")
print("")
print("")
print("############################################")
print("#   Image tagging Example                  #")
print("############################################")
print("")
print("")

print("Processing url: ", image_url)
print("")

response = alchemyapi.imageTagging("url", image_url)

if response["status"] == "OK":
    print("## Response Object ##")
    print(json.dumps(response, indent=4))

    print("")
    print("## Keywords ##")
    for keyword in response["imageKeywords"]:
        print(keyword["text"], " : ", keyword["score"])
    print("")
else:
    print("Error in image tagging call: ", response["statusInfo"])

print("")
print("")
コード例 #9
0
# Microformats
print('Checking microformats . . . ')
response = alchemyapi.microformats('text', test_text)
assert (response['status'] == 'ERROR')  # only works for html and url content
response = alchemyapi.microformats('html', test_html, {'url': 'test'})
assert (response['status'] == 'OK')
response = alchemyapi.microformats('url', test_url)
assert (response['status'] == 'OK')
print('Microformat tests complete!')
print('')
print('')

# imagetagging
print('Checking imagetagging . . . ')
response = alchemyapi.imageTagging('text', test_text)
assert (response['status'] == 'ERROR')
response = alchemyapi.imageTagging('html', test_html)
assert (response['status'] == 'ERROR')
response = alchemyapi.imageTagging('url', test_url)
assert (response['status'] == 'OK')
response = alchemyapi.imageTagging('image', test_jpg)
assert (response['status'] == 'OK')
print('Image tagging tests complete!')
print('')
print('')

# combined
print('Checking combined . . . ')
response = alchemyapi.combined('text', test_text)
assert (response['status'] == 'OK')