Commit c1e60236 authored by W.D.R.P. Sandeepa's avatar W.D.R.P. Sandeepa

Merge branch 'it18218640' into 'master'

It18218640

See merge request !51
parents e15b699d 654958e4
from flask import Flask
app = Flask(__name__)
from routes import *
app.register_blueprint(routes)
{
"name": "helply",
"ip": "127.0.0.1",
"user": "root",
"pwd": "12345678"
}
import mysql.connector
from sqlalchemy import create_engine
import pandas as pd
def create_con():
db = mysql.connector.connect(
database="helply",
host="127.0.0.1",
user="root",
password="rp19970520"
)
return db
def create_con_pandas():
db_connection_str = 'mysql+mysqlconnector://root:rp19970520@127.0.0.1/helply'
db = create_engine(db_connection_str)
return db
def insert_data_pandas_df(pd_df, table_name):
db = create_con_pandas()
pd_df.to_sql(name=table_name, con=db, if_exists='append', index=False)
def get_data_sql(sql):
db = create_con_pandas()
return pd.read_sql_query(sql=sql, con=db)
def insert_data_json(sql_query):
db = create_con()
cursor = db.cursor()
cursor.execute(sql_query)
db.commit()
db.close()
return "INFO: insert successful"
def insert_data(sql_query):
db = create_con()
cursor = db.cursor()
try:
cursor.execute(sql_query)
db.commit()
db.close()
return 1
except Exception as e:
db.rollback()
db.close()
print(e)
return e
def insert_data_get_id(sql_query):
db = create_con()
cursor = db.cursor()
try:
cursor.execute(sql_query)
id = cursor.lastrowid
db.commit()
db.close()
return 1, id
except Exception as e:
db.rollback()
db.close()
print(e)
return e
def insert_data_main_response(trip_info_sql, trip_df):
db = create_con()
cursor = db.cursor()
try:
cursor.execute(trip_info_sql)
insert_data_pandas_df(trip_df, 'trip')
db.commit()
db.close()
return 1
except Exception as e:
db.rollback()
db.close()
return e
def get_data(sql_query):
db = create_con()
cursor = db.cursor()
cursor.execute(sql_query)
results = cursor.fetchall()
db.close()
return results
def get_data_list(sql_query):
db = create_con()
cursor = db.cursor()
cursor.execute(sql_query)
results = list(cursor.fetchall())
db.close()
return results
def update_data(sql_query):
db = create_con()
cursor = db.cursor()
try:
cursor.execute(sql_query)
db.commit()
db.close()
return 1
except Exception as e:
db.rollback()
db.close()
print(e)
return e
from db.dbConnection import get_data_sql
#
#
def getColorActivities():
qry = 'SELECT * FROM coloractivities'
name = get_data_sql(qry).to_json()
return name
\ No newline at end of file
from flask import Blueprint
routes = Blueprint('routes', __name__)
from .reading import *
from .color import *
from . import routes
# from API.db.dbConnection import get_data_sql
from models.clorModel import getColorActivities
#
#
@routes.route("/colorActivities", methods=['GET'])
def ColorActivity():
return getColorActivities()
\ No newline at end of file
from . import routes
from db.dbConnection import get_data_sql
@routes.route("/", methods=['GET'])
def studentList():
x = 1
qry = 'SELECT name FROM student WHERE id = "{}"'.format(x)
name = get_data_sql(qry).to_json()
return name
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment