Hi Community,
Does anyone have a sample python script to select INDUSTRY CLASSIFICATION from TRKD?
Best,
Andrew
Hi Community,
Does anyone have a sample python script to select INDUSTRY CLASSIFICATION from TRKD?
Best,
Andrew
From theGet Industry Classification Schema Full Hierarchy call on TRKD catalog at LINK.
Here is the sample code:
import requests import json import sys appid = raw_input('Please input appid: ') token = raw_input('Please input token: ') requestMsg1 = \ { "GetIndustryClassificationSchemaFullHierarchy_Request_1": { "TaxonomyCode": "RBSS2004", "LanguageCode": "en-US" } } requestURL = 'http://api.trkd.thomsonreuters.com/api/Fundamentals/Fundamentals.svc/REST/Fundamentals_1/GetIndustryClassificationSchemaFullHierarchy_1' headers = {'content-type': 'application/json;charset=utf-8', 'X-Trkd-Auth-ApplicationID': appid, 'X-Trkd-Auth-Token': token} result = requests.post(requestURL, data = json.dumps(requestMsg1), headers=headers) resultText = result.text print resultText.encode(sys.stdout.encoding, errors='replace')
You can inspect the JSON sample request on the TRKD catalog and change the code accordingly.
Red circle is URL endpoint which your request will be sent to.
Pink circle is a token generated from TRKD Create Service Token call.
Blue circle is an application ID assigned to your login.
Green circle is an input.
Here is the sample code to generate a token:
import requests import json import getpass ##get username, password and applicationid username = raw_input('Please input username: ') ##use getpass.getpass to hide user inputted password password = getpass.getpass(prompt='Please input password: ') appid = raw_input('Please input appid: ') ##create authentication request URL, message and header #{ # "CreateServiceToken_Request_1":{ # "ApplicationID": <application id>, # "Username": <username>, # "Password": <password> # } #} authenMsg = {'CreateServiceToken_Request_1': { 'ApplicationID':appid, 'Username':username,'Password':password }} authenURL = 'https://api.trkd.thomsonreuters.com/api/TokenManagement/TokenManagement.svc/REST/Anonymous/TokenManagement_1/CreateServiceToken_1' headers = {'content-type': 'application/json;charset=utf-8'} #send request result = requests.post(authenURL, data = json.dumps(authenMsg), headers=headers) if result.status_code == 200: print 'Request success' print 'response status %s'%(result.status_code) ##get Token token = result.json()['CreateServiceToken_Response_1']['Token'] print 'Token: %s'%(token) ##get expiration expire = result.json()['CreateServiceToken_Response_1']['Expiration'] print 'Expire: %s'%(expire) elif result.status_code == 500: print 'Request fail' print 'response status %s'%(result.status_code) print 'Error: %s'%(result.json()) print result.text #{ # "CreateServiceToken_Response_1": { # "Expiration": "2016-09-26T09:42:54.4335265Z", # "Token": "xxxxxxxxxx..." # } #}