Skip to content

Commit cf0b4fc

Browse files
authored
using dotenv now - instead of cfg file
1 parent cfe625a commit cf0b4fc

File tree

1 file changed

+37
-21
lines changed

1 file changed

+37
-21
lines changed

Configuration/credentials.ipynb

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,37 @@
2727
},
2828
{
2929
"cell_type": "code",
30-
"execution_count": 1,
30+
"execution_count": 2,
3131
"metadata": {},
3232
"outputs": [],
3333
"source": [
34-
"APP_KEY = 'YOUR_APP_KEY'\n",
35-
"RDP_LOGIN = 'YOUR_REFINITIV_DATA_PLATFORM_LOGIN'\n",
36-
"RDP_PASSWORD = 'YOUR_REFINITIV_DATA_PLATFORM_PASSWORD'\n",
37-
"DEPLOYED_PLATFORM_HOST = 'THE_HOST:PORT_OF_YOUR_DEPLOYED_PLATFORM' # ADS hostname:PORT or IP:PORT e.g. 'myADS:15000'\n",
38-
"DEPLOYED_PLATFORM_USER_NAME = 'YOUR_USER_NAME_ON_YOUR_DEPLOYED_PLATFORM' # DACS user name "
39-
]
40-
},
41-
{
42-
"cell_type": "markdown",
43-
"metadata": {},
44-
"source": [
45-
" "
34+
"#import logging\n",
35+
"#import sys\n",
36+
"#file_handler = logging.FileHandler(filename='c:/Temp/tmp.log')\n",
37+
"#handlers = [file_handler]\n",
38+
"#logging.basicConfig(\n",
39+
"# level=logging.DEBUG, \n",
40+
"# format='[%(asctime)s] {%(filename)s:%(lineno)d} %(levelname)s - %(message)s',\n",
41+
"# handlers=handlers\n",
42+
"#)\n",
43+
"\n",
44+
"import logging.config\n",
45+
"import os\n",
46+
"from dotenv import load_dotenv\n",
47+
"\n",
48+
"# load credentials from a .env file (+ override any OS system env vars of the same name)\n",
49+
"load_dotenv(override=True)\n",
50+
"APP_KEY = os.getenv('APP_KEY')\n",
51+
"RDP_LOGIN = os.getenv('RDP_LOGIN')\n",
52+
"RDP_PASSWORD = os.getenv('RDP_PASSWORD')\n",
53+
"DEPLOYED_PLATFORM_HOST = os.getenv('DEPLOYED_PLATFORM_HOST')\n",
54+
"DEPLOYED_PLATFORM_USER_NAME = os.getenv('DEPLOYED_PLATFORM_USER_NAME')\n",
55+
"\n",
56+
"#APP_KEY = 'YOUR_APP_KEY'\n",
57+
"#RDP_LOGIN = 'YOUR_REFINITIV_DATA_PLATFORM_LOGIN'\n",
58+
"#RDP_PASSWORD = 'YOUR_REFINITIV_DATA_PLATFORM_PASSWORD'\n",
59+
"#DEPLOYED_PLATFORM_HOST = 'THE_HOST:PORT_OF_YOUR_DEPLOYED_PLATFORM' # ADS hostname:PORT or IP:PORT e.g. 'myADS:15000'\n",
60+
"#DEPLOYED_PLATFORM_USER_NAME = 'YOUR_USER_NAME_ON_YOUR_DEPLOYED_PLATFORM' # DACS user name "
4661
]
4762
},
4863
{
@@ -54,9 +69,9 @@
5469
"These function will be used by most of the other tutorials to reduce session related code replication.\n",
5570
"\n",
5671
"Set your default session_type below with **SESSION_TYPE** variable below - valid values are:\n",
57-
"- \"**desktop**\"\n",
58-
"- \"**rdp**\"\n",
59-
"- \"**deployed**\" \n",
72+
"- \"desktop\"\n",
73+
"- \"rdp\"\n",
74+
"- \"deployed\" \n",
6075
"\n",
6176
"This will avoid the need to specif it in all the tutorials.\n",
6277
"\n",
@@ -69,7 +84,7 @@
6984
},
7085
{
7186
"cell_type": "code",
72-
"execution_count": null,
87+
"execution_count": 3,
7388
"metadata": {
7489
"tags": []
7590
},
@@ -87,7 +102,7 @@
87102
" session = get_default_session()\n",
88103
" if session is None:\n",
89104
" if session_type == \"desktop\":\n",
90-
" session = rd.session.desktop.Definition(APP_KEY).get_session()\n",
105+
" session = rd.session.desktop.Definition(app_key=APP_KEY).get_session()\n",
91106
" elif session_type == \"rdp\":\n",
92107
" session = rd.session.platform.Definition(\n",
93108
" app_key=APP_KEY,\n",
@@ -106,11 +121,12 @@
106121
" if session is None:\n",
107122
" raise Exception(f\"Wrong session_type: {session_type}. It must be ['desktop', 'rdp', 'deployed']\")\n",
108123
" else:\n",
109-
" set_default_session(session)\n",
110124
" #session.set_log_level(logging.DEBUG)\n",
111-
" session.set_log_level(logging.WARNING)\n",
125+
" session.set_log_level(logging.ERROR)\n",
126+
" set_default_session(session)\n",
112127
" session.open()\n",
113-
" \n",
128+
" return session\n",
129+
" \n",
114130
"def close_session():\n",
115131
" session = get_default_session()\n",
116132
" if session:\n",

0 commit comments

Comments
 (0)