Wednesday, August 7, 2019

Python and Jupiter Notebook : How to connect Oracle DB using cx_oracle and save the data into a csv file

import cx_Oracle

# Connect as user "hr" with password "welcome" to the "oraclepdb" service running on this computer.
connection = cx_Oracle.connect("username", "*******", "pdatabasename:1521/DBNAME")

cursor = connection.cursor()

cursor.execute("""
    SELECT profile_id,first_name, last_name
    FROM t_profile
    WHERE rownum<= :run """,
    run = 50)

res = cursor.fetchall()
cursor.close()

print (res)

import pandas as pd
df_ora = pd.read_sql('SELECT profile_id,first_name, last_name FROM t_profile WHERE rownum<= 50', con=connection) 
df_ora

df_ora.to_csv('data_from_ora.csv',index=False,header=True)

df_ora.info()

Basic  Flask program : Just a start flask program

import os
import json
from flask import Flask
from flask import jsonify

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello World!'
@app.route('/foo')
def foo():
    return 'bar'
@app.route('/hi/<name>')
def hi(name):
    return f'Hi {name}!'

@app.route('/api')
def api():
    data = {
        'name': 'Andrew',
        'user': 'acroz'
    }
    return jsonify(data)


if __name__ == '__main__':
    app.run(debug=True)

Must Watch YouTube Videos for Databricks Platform Administrators

  While written word is clearly the medium of choice for this platform, sometimes a picture or a video can be worth 1,000 words. Below are  ...