|
1 | 1 | import os |
2 | 2 | import json |
3 | 3 | import sys |
| 4 | +import argparse |
4 | 5 | from dotenv import load_dotenv |
5 | | -from icecream import ic |
6 | 6 | import requests |
7 | 7 |
|
8 | 8 | if __name__ == '__main__': |
9 | 9 |
|
| 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 | + |
10 | 20 | client_secret = '' |
11 | 21 | scope = 'trapi' |
12 | | - universe = '7203.T' |
13 | 22 | auth_obj = None |
14 | 23 |
|
15 | | - load_dotenv() |
16 | | - |
17 | 24 | # Get RDP Token service information from Environment Variables |
18 | 25 | base_URL = os.getenv('RDP_BASE_URL') |
19 | 26 | auth_endpoint = base_URL + os.getenv('RDP_AUTH_URL') |
|
26 | 33 | # -- Init and Authenticate Session |
27 | 34 | auth_request_msg = { |
28 | 35 | 'username': username , |
29 | | - 'password': 'password' , |
| 36 | + 'password': password , |
30 | 37 | 'grant_type': "password", |
31 | 38 | 'scope': scope, |
32 | 39 | 'takeExclusiveSignOnControl': "true" |
33 | 40 | } |
34 | 41 |
|
| 42 | + # Authentication with RDP Auth Service |
35 | 43 | try: |
36 | 44 | response = requests.post(auth_endpoint, headers = {'Accept':'application/json'}, data = auth_request_msg, auth = (app_key, client_secret)) |
37 | 45 | except Exception as exp: |
38 | | - ic('Caught exception: %s' % str(exp)) |
| 46 | + print('Caught exception: %s' % str(exp)) |
39 | 47 |
|
40 | 48 | if response.status_code == 200: # HTTP Status 'OK' |
41 | 49 | print('Authentication success') |
|
44 | 52 | print('RDP authentication result failure: %s %s' % (response.status_code, response.reason)) |
45 | 53 | print('Text: %s' % (response.text)) |
46 | 54 |
|
| 55 | + # If authentication fail, exit program. |
47 | 56 | if auth_obj is None: |
48 | 57 | print('Authentication fail, exit program') |
49 | 58 | sys.exit(0) |
|
53 | 62 |
|
54 | 63 | payload = {'universe': universe} |
55 | 64 | esg_object = None |
| 65 | + |
| 66 | + # Request data for ESG Score Full Service |
56 | 67 | 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) |
58 | 69 | except Exception as exp: |
59 | 70 | print('Caught exception: %s' % str(exp)) |
60 | 71 |
|
|
68 | 79 |
|
69 | 80 | print('\n') |
70 | 81 |
|
| 82 | + # If ESG Data available, convert data to Pandas DataFrame |
71 | 83 | if esg_object is not None: |
72 | 84 | # https://developers.refinitiv.com/en/article-catalog/article/using-rdp-api-request-esg-data-jupyter-notebook |
73 | 85 | import pandas as pd |
|
0 commit comments