python Alchemy News Api使用python调用

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Alchemy News Api使用python调用相关的知识,希望对你有一定的参考价值。

'''
A basic implementation of calling Alchemy API using python.
I have used request library but you can use urllib too
'''

import requests
import json 
from BeautifulSoup import BeautifulSoup



sentiments = 'any positive negative neutral'
sentiments = sentiments.split()

types = 'free text person city company organization'
types = types.split()

api_key = "cdad43590134920e8f031aeca32b196f1296d637"

def news_api(text, type, sentiment_type,):
    
    url="https://access.alchemyapi.com/calls/data/GetNews?apikey="+api_key+"\
&return=enriched.url.title&start=1431561600&end=1432249200&q.enriched.url.enrichedTitle.entities.entity=|\
text="+text+",type="+type+"|&q.enriched.url.enrichedTitle.docSentiment.type="+sentiment_type+"&q.enriched.url.enrichedTitle.taxonomy.taxonomy_.label=technology%20and%20computing&count=25&outputMode=json"
    print url
    s = requests.get(url).text;
    print s
    
news_api("IBM Mainframes", types[0], "positive")   



'''
taxonomy label: 
any
art and entertainment
automotive and vehicles
business and industrial
careers
education
family and parenting
finance
food and drink
health and fitness
hobbies and interests
home and garden
law, govt and politics
news
pets
real estate
religion and spirituality
science
shopping
society
sports
style and fashion
technology and computing
travel
'''

以上是关于python Alchemy News Api使用python调用的主要内容,如果未能解决你的问题,请参考以下文章

python Alchemy News Api使用python调用

python Alchemy News Api使用python调用

Alchemy News API 中的其他数据源

如何监控 Bluemix 上 Alchemy API 服务的每日 API 事务使用情况?

使用blob在python中将pdf上传到sql-alchemy

python 如何使用SQL Alchemy编译INSERT ... ON DUPLICATE KEY UPDATE并支持批量插入。