search.py 1.05 KB
from flask import jsonify, Response
import json
import cx_Oracle
import os
from config.key import DATABASE_ID, DATABASE_PW
from config.URLs import DATABASE_URL


def search(insta_id):
    connection = cx_Oracle.connect(DATABASE_ID, DATABASE_PW, DATABASE_URL)
    cursor = connection.cursor()

    cursor.execute(f"""
        select * from users where user_id=\'{insta_id}\'
    """)
    exist_user = cursor.fetchall()
    print(exist_user)
    cursor.execute(f"""
        select * from followers where user_id=\'{insta_id}\'
    """)
    exist_followers = cursor.fetchall()
    print(exist_followers)
    exist_info = ()
    if len(exist_user) > 0:
        exist_info = {
            "user": exist_user[0],
            "follower": exist_followers
        }

    print(exist_info)

    cursor.close()

    return Response(json.dumps(exist_info), mimetype='application/json')


if __name__ == '__main__':
    os.putenv('NLS_LANG', '.UTF8')
    cx_Oracle.init_oracle_client(lib_dir="/Users/choewonseog/Downloads/instantclient_19_8")
    print(search('__re.mind.er__').data)