Last active
October 11, 2016 23:24
-
-
Save remkohdev/99c660d02db3a03ab9c9b9a45025e9d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http.client | |
import csv | |
apikey = "<your-apikey>" | |
def GetNews(searchterm=None, outputMode="json", startdate=None, enddate=None, count="5", returnfields="enriched.url.url"): | |
conn = http.client.HTTPSConnection("gateway-a.watsonplatform.net") | |
headers = { | |
'content-type': "application/json" | |
} | |
endpoint = ('/calls/data/GetNews?outputMode={0}&start={1}&end={2}&count={3}&q.enriched.url.enrichedTitle.keywords.keyword.text={4}&return={5}&apikey={6}').format(outputMode, startdate, enddate, count, searchterm, returnfields, apikey) | |
print("GetNews API. endpoint: %s", endpoint) | |
conn.request("GET", endpoint, headers=headers) | |
res = conn.getresponse() | |
logMsg = ("GetNews API. response: status[{0}], msg[{1}], reason[{2}]").format(res.status, res.msg, res.reason) | |
print(logMsg) | |
# HTTPResponse.read returns bytes[] | |
data = res.read() | |
responseStr = data.decode("utf-8") | |
return responseStr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment