コード例 #1
0
def process(input, entities):
    output = {}
    try:
        book_title = entities['book'][0]['value']
        response = requests.get(
            'https://www.goodreads.com/book/title.xml?key=' +
            GOODREADS_ACCESS_TOKEN + '&title=' + book_title)
        data = ElementTree.fromstring(response.content)

        book_node = data.find('book')
        title = book_node.find('title').text
        description = book_node.find('description').text
        average_rating = book_node.find('average_rating').text
        link = book_node.find('link').text
        goodreads_attribution = "- Powered by Goodreads"

        template = TextTemplate()
        template.set_text('Title: ' + title + '\nDescription: ' + description)
        template.set_post_text('\nAverage Rating: ' + average_rating +
                               '\nLink: ' + link + '\n\n' +
                               goodreads_attribution)

        output['input'] = input
        output['output'] = template.get_message()
        output['success'] = True
    except:
        output['success'] = False
    return output
コード例 #2
0
ファイル: book.py プロジェクト: pv2k/JARVIS-on-Messenger
def process(input, entities):
    output = {}
    try:
        book_title = entities['book'][0]['value']
        response = requests.get('https://www.goodreads.com/book/title.xml?key=' + GOODREADS_ACCESS_TOKEN + '&title=' + book_title)
        data = ElementTree.fromstring(response.content)

        book_node = data.find('book')
        title = book_node.find('title').text
        description = book_node.find('description').text
        average_rating = book_node.find('average_rating').text
        link = book_node.find('link').text
        goodreads_attribution = '- Powered by Goodreads'

        template = TextTemplate()
        template.set_text('Title: ' + title + '\nDescription: ' + description)
        template.set_post_text('\nAverage Rating: ' + average_rating + ' / 5' + '\nLink: ' + link + '\n\n' + goodreads_attribution)

        output['input'] = input
        output['output'] = template.get_message()
        output['success'] = True
    except:
        error_message = 'I couldn\'t find any book matching your query.'
        error_message += '\nPlease ask me something else, like:'
        error_message += '\n  - book timeline'
        error_message += '\n  - harry potter book plot'
        error_message += '\n  - little women book rating'
        output['error_msg'] = TextTemplate(error_message).get_message()
        output['success'] = False
    return output
コード例 #3
0
def process(input, entities):
    output = {}
    try:
        query = entities['wikipedia_search_query'][0]['value']
        data = wikipedia.page(query)
        template = TextTemplate()
        template.set_text('Wikipedia summary of ' + data.title + ':\n' + data.summary)
        template.set_post_text('\n' + data.url)
        output['input'] = input
        output['output'] = template.get_message()
        output['success'] = True
    except:
        output['success'] = False
    return output
コード例 #4
0
def process(input, entities):
    output = {}
    try:
        movie = entities['movie'][0]['value']
        r = requests.get('http://www.omdbapi.com/?t=' + movie + '&plot=full&r=json')
        data = r.json()
        output['input'] = input
        template = TextTemplate()
        template.set_text(data['Title'] + '\nPlot: ' + data['Plot'])
        template.set_post_text('\nIMDb Rating: ' + data['imdbRating'])
        output['output'] = template.get_message()
        output['success'] = True
    except:
        output['success'] = False
    return output
コード例 #5
0
def process(input, entities):
    output = {}
    try:
        movie = entities['movie'][0]['value']
        r = requests.get('http://www.omdbapi.com/?t=' + movie +
                         '&plot=full&r=json')
        data = r.json()
        output['input'] = input
        template = TextTemplate()
        template.set_text(data['Title'] + '\nPlot: ' + data['Plot'])
        template.set_post_text('\nIMDb Rating: ' + data['imdbRating'])
        output['output'] = template.get_message()
        output['success'] = True
    except:
        output['success'] = False
    return output
コード例 #6
0
ファイル: scores.py プロジェクト: grishabh96/Minorproject1
def process(input, entities=None):
    output = {}
    source = 'cricketScore'  # Can add more sources in future
    try:

        r = requests.get('http://cricapi.com/api/matches/' + SCORES_API_KEY)
        data1 = r.json()
        assert (len(data1['matches']) > 0)
        now = datetime.datetime.now()
        p = now.isoformat()
        for match in data1['matches']:
            if p is match['date']:
                id = match['unique_id']
                team1 = match['team-1']
                team2 = match['team-2']
                template = TextTemplate()
                d = requests.get('http://cricapi.com/api/cricketScore?' +
                                 'unique_id=' + id,
                                 params={'apikey': SCORES_API_KEY})
                data2 = d.json()
                count = 0
                assert (len(data2['data']) > 0)
                for scores in data2['data']:
                    count = count + 1
                    score = scores['score']
                    template.set_text('Here are the scores of match between' +
                                      team1 + ' and ' + team2 + ':\n' + score)
                    template.set_post_text('\n- Powered by MusiXmatch')
                    template.set_limit(TEXT_CHARACTER_LIMIT)

                    template = ButtonTemplate(template.get_text())
                    output['input'] = input
                    output['output'][count - 1] = template.get_message()
                    output['success'] = True
    except:
        error_message = 'There was some error while retrieving data from NewsAPI.'
        output['error_msg'] = TextTemplate(error_message).get_message()
        output['success'] = False
    return output
コード例 #7
0
def process(input, entities=None):
    output = {}
    try:
        book_title = entities['book'][0]['value']
        response = requests.get('https://www.goodreads.com/book/title.xml?key=' + GOODREADS_ACCESS_TOKEN + '&title=' + book_title)
        data = ElementTree.fromstring(response.content)

        book_node = data.find('book')
        title = book_node.find('title').text
        description = book_node.find('description').text
        average_rating = book_node.find('average_rating').text
        link = book_node.find('link').text
        goodreads_attribution = "- Powered by Goodreads"

        template = TextTemplate()
        template.set_text('Title: ' + title + '\nDescription: ' + description)
        template.set_post_text('\nAverage Rating: ' + average_rating + '\nLink: ' + link + '\n\n' + goodreads_attribution)

        output['input'] = input
        output['output'] = template.get_message()
        output['success'] = True
    except:
        output['success'] = False
    return output