Skip to content

Commit df17c5c

Browse files
committed
add cli support
1 parent 521e3c0 commit df17c5c

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

Python/rdp_apis_console.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
import os
22
import json
33
import sys
4+
import argparse
45
from dotenv import load_dotenv
5-
from icecream import ic
66
import requests
77

88
if __name__ == '__main__':
99

10+
# Load Environment Variables
11+
load_dotenv()
12+
13+
# Build and Parse Command line arguments for item/universe, which always change.
14+
my_parser = argparse.ArgumentParser(description='Interested Symbol')
15+
my_parser.add_argument('-i','--item', type = str, default= 'LSEG.L')
16+
args = my_parser.parse_args()
17+
18+
universe = args.item
19+
1020
client_secret = ''
1121
scope = 'trapi'
12-
universe = '7203.T'
1322
auth_obj = None
1423

15-
load_dotenv()
16-
1724
# Get RDP Token service information from Environment Variables
1825
base_URL = os.getenv('RDP_BASE_URL')
1926
auth_endpoint = base_URL + os.getenv('RDP_AUTH_URL')
@@ -26,16 +33,17 @@
2633
# -- Init and Authenticate Session
2734
auth_request_msg = {
2835
'username': username ,
29-
'password': 'password' ,
36+
'password': password ,
3037
'grant_type': "password",
3138
'scope': scope,
3239
'takeExclusiveSignOnControl': "true"
3340
}
3441

42+
# Authentication with RDP Auth Service
3543
try:
3644
response = requests.post(auth_endpoint, headers = {'Accept':'application/json'}, data = auth_request_msg, auth = (app_key, client_secret))
3745
except Exception as exp:
38-
ic('Caught exception: %s' % str(exp))
46+
print('Caught exception: %s' % str(exp))
3947

4048
if response.status_code == 200: # HTTP Status 'OK'
4149
print('Authentication success')
@@ -44,6 +52,7 @@
4452
print('RDP authentication result failure: %s %s' % (response.status_code, response.reason))
4553
print('Text: %s' % (response.text))
4654

55+
# If authentication fail, exit program.
4756
if auth_obj is None:
4857
print('Authentication fail, exit program')
4958
sys.exit(0)
@@ -53,8 +62,10 @@
5362

5463
payload = {'universe': universe}
5564
esg_object = None
65+
66+
# Request data for ESG Score Full Service
5667
try:
57-
response = requests.get(esg_url, headers={'Authorization': 'Bearer {}'.format(auth_obj['refresh_token'])}, params = payload)
68+
response = requests.get(esg_url, headers={'Authorization': 'Bearer {}'.format(auth_obj['access_token'])}, params = payload)
5869
except Exception as exp:
5970
print('Caught exception: %s' % str(exp))
6071

@@ -68,6 +79,7 @@
6879

6980
print('\n')
7081

82+
# If ESG Data available, convert data to Pandas DataFrame
7183
if esg_object is not None:
7284
# https://developers.refinitiv.com/en/article-catalog/article/using-rdp-api-request-esg-data-jupyter-notebook
7385
import pandas as pd

0 commit comments

Comments
 (0)