|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "id": "306bfc7c-da99-4221-aba4-1932c2810ed2", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "import pandas as pd\n", |
| 11 | + "import pyodbc\n", |
| 12 | + "from getpass import getpass" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "code", |
| 17 | + "execution_count": 2, |
| 18 | + "id": "c1b19fba-c9ea-4eec-8e8e-0c0cdac05608", |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [ |
| 21 | + { |
| 22 | + "name": "stdout", |
| 23 | + "output_type": "stream", |
| 24 | + "text": [ |
| 25 | + "Python 3.8.10 (default, May 19 2021, 13:12:57) [MSC v.1916 64 bit (AMD64)]\n" |
| 26 | + ] |
| 27 | + } |
| 28 | + ], |
| 29 | + "source": [ |
| 30 | + "!python -V -V" |
| 31 | + ] |
| 32 | + }, |
| 33 | + { |
| 34 | + "cell_type": "code", |
| 35 | + "execution_count": 3, |
| 36 | + "id": "12816fcf-4778-45d9-8265-3d0966f24a5b", |
| 37 | + "metadata": {}, |
| 38 | + "outputs": [], |
| 39 | + "source": [ |
| 40 | + "dsn = 'SRMDB_P'" |
| 41 | + ] |
| 42 | + }, |
| 43 | + { |
| 44 | + "cell_type": "code", |
| 45 | + "execution_count": 4, |
| 46 | + "id": "8051234e-1432-4bed-9001-8c27b2b826f0", |
| 47 | + "metadata": {}, |
| 48 | + "outputs": [ |
| 49 | + { |
| 50 | + "name": "stdin", |
| 51 | + "output_type": "stream", |
| 52 | + "text": [ |
| 53 | + "Enter your mainframe password: ········\n" |
| 54 | + ] |
| 55 | + } |
| 56 | + ], |
| 57 | + "source": [ |
| 58 | + "user = 'nmdpur'\n", |
| 59 | + "pwd = getpass(\"Enter your mainframe password:\")" |
| 60 | + ] |
| 61 | + }, |
| 62 | + { |
| 63 | + "cell_type": "code", |
| 64 | + "execution_count": 5, |
| 65 | + "id": "b5ca1cec-8a48-47e7-bcc1-dd3fe378f3e3", |
| 66 | + "metadata": {}, |
| 67 | + "outputs": [], |
| 68 | + "source": [ |
| 69 | + "sql = \"\"\"\n", |
| 70 | + "SELECT\n", |
| 71 | + " CURRENT TIMESTAMP as DATETIME_NOW\n", |
| 72 | + "FROM\n", |
| 73 | + " SYSIBM.SYSDUMMY1\n", |
| 74 | + "\"\"\"" |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "code", |
| 79 | + "execution_count": 6, |
| 80 | + "id": "ca61b9c4-0ab4-4ebd-a975-a0ee94a6b1a1", |
| 81 | + "metadata": {}, |
| 82 | + "outputs": [], |
| 83 | + "source": [ |
| 84 | + "# Execute query and save results as a pandas dataframe\n", |
| 85 | + "with pyodbc.connect(f'DSN={dsn};UID={user};PWD={pwd}') as conn:\n", |
| 86 | + " df = pd.read_sql(sql, conn)" |
| 87 | + ] |
| 88 | + }, |
| 89 | + { |
| 90 | + "cell_type": "code", |
| 91 | + "execution_count": 7, |
| 92 | + "id": "e70e4228-6405-4c63-9c13-75a6013a8988", |
| 93 | + "metadata": {}, |
| 94 | + "outputs": [ |
| 95 | + { |
| 96 | + "data": { |
| 97 | + "text/html": [ |
| 98 | + "<div>\n", |
| 99 | + "<style scoped>\n", |
| 100 | + " .dataframe tbody tr th:only-of-type {\n", |
| 101 | + " vertical-align: middle;\n", |
| 102 | + " }\n", |
| 103 | + "\n", |
| 104 | + " .dataframe tbody tr th {\n", |
| 105 | + " vertical-align: top;\n", |
| 106 | + " }\n", |
| 107 | + "\n", |
| 108 | + " .dataframe thead th {\n", |
| 109 | + " text-align: right;\n", |
| 110 | + " }\n", |
| 111 | + "</style>\n", |
| 112 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 113 | + " <thead>\n", |
| 114 | + " <tr style=\"text-align: right;\">\n", |
| 115 | + " <th></th>\n", |
| 116 | + " <th>DATETIME_NOW</th>\n", |
| 117 | + " </tr>\n", |
| 118 | + " </thead>\n", |
| 119 | + " <tbody>\n", |
| 120 | + " <tr>\n", |
| 121 | + " <th>0</th>\n", |
| 122 | + " <td>2021-05-21 17:52:06.436452</td>\n", |
| 123 | + " </tr>\n", |
| 124 | + " </tbody>\n", |
| 125 | + "</table>\n", |
| 126 | + "</div>" |
| 127 | + ], |
| 128 | + "text/plain": [ |
| 129 | + " DATETIME_NOW\n", |
| 130 | + "0 2021-05-21 17:52:06.436452" |
| 131 | + ] |
| 132 | + }, |
| 133 | + "execution_count": 7, |
| 134 | + "metadata": {}, |
| 135 | + "output_type": "execute_result" |
| 136 | + } |
| 137 | + ], |
| 138 | + "source": [ |
| 139 | + "df.head()" |
| 140 | + ] |
| 141 | + } |
| 142 | + ], |
| 143 | + "metadata": { |
| 144 | + "kernelspec": { |
| 145 | + "display_name": "Py3.9 (data_eval)", |
| 146 | + "language": "python", |
| 147 | + "name": "data_eval" |
| 148 | + }, |
| 149 | + "language_info": { |
| 150 | + "codemirror_mode": { |
| 151 | + "name": "ipython", |
| 152 | + "version": 3 |
| 153 | + }, |
| 154 | + "file_extension": ".py", |
| 155 | + "mimetype": "text/x-python", |
| 156 | + "name": "python", |
| 157 | + "nbconvert_exporter": "python", |
| 158 | + "pygments_lexer": "ipython3", |
| 159 | + "version": "3.9.8" |
| 160 | + } |
| 161 | + }, |
| 162 | + "nbformat": 4, |
| 163 | + "nbformat_minor": 5 |
| 164 | +} |
0 commit comments