#!/usr/bin/env python
# coding: utf-8

import flask 
from flask import Flask, jsonify, request, send_from_directory
from flask_cors import CORS
import sqlite3  
import datetime
import numpy as np


app = Flask(__name__)  #initilazation
CORS(app)


@app.route('/')
def default_route():
    return "Hello This is the Default Route"
    
@app.route('/sbiLife', methods= ['GET'])
def fetch_data():
    toDate = request.args.get("toDate") 
    fromDate = request.args.get("fromDate")
    toDate = toDate if toDate.split('-')[1] !='Sept' else toDate.replace('Sept', 'Sep')
    fromDate = fromDate if fromDate.split('-')[1] !='Sept' else fromDate.replace('Sept', 'Sep')
    try:
        toDate = datetime.datetime.strptime(toDate, '%d-%b-%Y').strftime('%Y-%m-%d %H:%M:%S')
        fromDate = datetime.datetime.strptime(fromDate, '%d-%b-%Y').strftime('%Y-%m-%d %H:%M:%S')
        con = sqlite3.connect(r"D:\data\investment.db")
        cur = con.cursor()
        date,balance,bond,corporate,equity,growth,midcap = [],[],[],[],[],[],[]
        for row in cur.execute("SELECT * FROM investment WHERE date BETWEEN :fromDate AND :toDate",{"fromDate":fromDate, "toDate":toDate}):
            date.append(datetime.datetime.strptime(row[1], '%Y-%m-%d %H:%M:%S').strftime('%d-%m-%Y'))
            balance.append(row[2])
            bond.append(row[3])
            corporate.append(row[4])
            equity.append(row[5])
            growth.append(row[6])
            midcap.append(row[7])
        balance,bond,corporate,equity,growth,midcap = np.array(balance)/balance[0], np.array(bond)/bond[0], np.array(corporate)/corporate[0], np.array(equity)/equity[0], np.array(growth)/growth[0], np.array(midcap)/midcap[0]
        return jsonify({"success": True, "message": 'Successfully Fetched' ,"date":date, "balance":list((balance-1)*100),"bond":list((bond-1)*100),"corporate":list((corporate-1)*100),"equity":list((equity-1)*100),"growth":list((growth-1)*100),"midcap":list((midcap-1)*100)})
        
    except Exception as e:
        return jsonify({"success": False, "message": str(e)})

@app.route('/sbiMutual', methods= ['GET'])
def fetch_mutual_data():
    toDate = request.args.get("toDate") 
    fromDate = request.args.get("fromDate")
    toDate = toDate if toDate.split('-')[1] !='Sept' else toDate.replace('Sept', 'Sep')
    fromDate = fromDate if fromDate.split('-')[1] !='Sept' else fromDate.replace('Sept', 'Sep')
    try:
        toDate = datetime.datetime.strptime(toDate, '%d-%b-%Y').strftime('%Y-%m-%d %H:%M:%S')
        fromDate = datetime.datetime.strptime(fromDate, '%d-%b-%Y').strftime('%Y-%m-%d %H:%M:%S')
        con = sqlite3.connect(r"D:\data\investment.db")
        cur = con.cursor()
        date,hybrid,equity,midcap,smallcap, focused, large = [],[],[],[],[],[],[]
        for row in cur.execute("SELECT * FROM investment_mutual WHERE date BETWEEN :fromDate AND :toDate",{"fromDate":fromDate, "toDate":toDate}):
            date.append(datetime.datetime.strptime(row[1], '%Y-%m-%d %H:%M:%S').strftime('%d-%m-%Y'))
            hybrid.append(row[2])
            equity.append(row[3])
            midcap.append(row[4])
            smallcap.append(row[5])
            focused.append(row[6])
            large.append(row[7])
        hybrid, equity, midcap, smallcap, focused, large = np.array(hybrid)/hybrid[0], np.array(equity)/equity[0], np.array(midcap)/midcap[0], np.array(smallcap)/smallcap[0], np.array(focused)/focused[0], np.array(large)/large[0]
        return jsonify({"success": True, "message": 'Successfully Fetched' ,"date":date, "hybrid":list((hybrid-1)*100),"magEquity":list((equity-1)*100),"magMidcap":list((midcap-1)*100),"smallcap":list((smallcap-1)*100), "focused": list((focused-1)*100), "large": list((large-1)*100)})
        
    except Exception as e:
        return jsonify({"success": False, "message": str(e)})


if __name__=="__main__":
    app.run()







#!/usr/bin/env python
# coding: utf-8

import flask 
from flask import Flask, jsonify, request, send_from_directory
from flask_cors import CORS
import sqlite3  
import datetime
import numpy as np


app = Flask(__name__)  #initilazation
CORS(app)


@app.route('/')
def default_route():
    return "Hello This is the Default Route"
    
@app.route('/sbiLife', methods= ['GET'])
def fetch_data():
    toDate = request.args.get("toDate") 
    fromDate = request.args.get("fromDate")
    toDate = toDate if toDate.split('-')[1] !='Sept' else toDate.replace('Sept', 'Sep')
    fromDate = fromDate if fromDate.split('-')[1] !='Sept' else fromDate.replace('Sept', 'Sep')
    try:
        toDate = datetime.datetime.strptime(toDate, '%d-%b-%Y').strftime('%Y-%m-%d %H:%M:%S')
        fromDate = datetime.datetime.strptime(fromDate, '%d-%b-%Y').strftime('%Y-%m-%d %H:%M:%S')
        con = sqlite3.connect(r"D:\data\investment.db")
        cur = con.cursor()
        date,balance,bond,corporate,equity,growth,midcap = [],[],[],[],[],[],[]
        for row in cur.execute("SELECT * FROM investment WHERE date BETWEEN :fromDate AND :toDate",{"fromDate":fromDate, "toDate":toDate}):
            date.append(datetime.datetime.strptime(row[1], '%Y-%m-%d %H:%M:%S').strftime('%d-%m-%Y'))
            balance.append(row[2])
            bond.append(row[3])
            corporate.append(row[4])
            equity.append(row[5])
            growth.append(row[6])
            midcap.append(row[7])
        balance,bond,corporate,equity,growth,midcap = np.array(balance)/balance[0], np.array(bond)/bond[0], np.array(corporate)/corporate[0], np.array(equity)/equity[0], np.array(growth)/growth[0], np.array(midcap)/midcap[0]
        return jsonify({"success": True, "message": 'Successfully Fetched' ,"date":date, "balance":list((balance-1)*100),"bond":list((bond-1)*100),"corporate":list((corporate-1)*100),"equity":list((equity-1)*100),"growth":list((growth-1)*100),"midcap":list((midcap-1)*100)})
        
    except Exception as e:
        return jsonify({"success": False, "message": str(e)})

@app.route('/sbiMutual', methods= ['GET'])
def fetch_mutual_data():
    toDate = request.args.get("toDate") 
    fromDate = request.args.get("fromDate")
    toDate = toDate if toDate.split('-')[1] !='Sept' else toDate.replace('Sept', 'Sep')
    fromDate = fromDate if fromDate.split('-')[1] !='Sept' else fromDate.replace('Sept', 'Sep')
    try:
        toDate = datetime.datetime.strptime(toDate, '%d-%b-%Y').strftime('%Y-%m-%d %H:%M:%S')
        fromDate = datetime.datetime.strptime(fromDate, '%d-%b-%Y').strftime('%Y-%m-%d %H:%M:%S')
        con = sqlite3.connect(r"D:\data\investment.db")
        cur = con.cursor()
        date,hybrid,equity,midcap,smallcap, focused, large = [],[],[],[],[],[],[]
        for row in cur.execute("SELECT * FROM investment_mutual WHERE date BETWEEN :fromDate AND :toDate",{"fromDate":fromDate, "toDate":toDate}):
            date.append(datetime.datetime.strptime(row[1], '%Y-%m-%d %H:%M:%S').strftime('%d-%m-%Y'))
            hybrid.append(row[2])
            equity.append(row[3])
            midcap.append(row[4])
            smallcap.append(row[5])
            focused.append(row[6])
            large.append(row[7])
        hybrid, equity, midcap, smallcap, focused, large = np.array(hybrid)/hybrid[0], np.array(equity)/equity[0], np.array(midcap)/midcap[0], np.array(smallcap)/smallcap[0], np.array(focused)/focused[0], np.array(large)/large[0]
        return jsonify({"success": True, "message": 'Successfully Fetched' ,"date":date, "hybrid":list((hybrid-1)*100),"magEquity":list((equity-1)*100),"magMidcap":list((midcap-1)*100),"smallcap":list((smallcap-1)*100), "focused": list((focused-1)*100), "large": list((large-1)*100)})
        
    except Exception as e:
        return jsonify({"success": False, "message": str(e)})


if __name__=="__main__":
    app.run()







#!/usr/bin/env python # coding: utf-8 #initilazation