def insert_table(): content = json.loads(request.data) if not content or not 'name' in content: abort(404) database = CreateDB(hostname = 'localhost') db.create_all() date_strptime = datetime.strptime(content['submit_date'], '%d-%m-%Y') user = User(content['id'],content['name'],content['email'],content['category'], content['description'],content['link'],content['estimated_costs'], date_strptime) db.session.add(user) db.session.commit() user_dict = { "id" : user.id, "name" : user.name, "email" : user.email, "category" : user.category, "description" : user.description, "link" : user.link, "estimated_costs" : user.estimated_costs, "submit_date" : user.submit_date.strftime('%d-%m-%Y'), "status" : user.status, "decision_date" : user.decision_date.strftime('%d-%m-%Y') } return json.dumps(user_dict), 201
def post(): CreateDB(hostname='mysqlserver') db.create_all() data = request.get_json(force=True) name = data['name'] email = data['email'] category = data['category'] description = data['description'] link = data['link'] estimated_costs = data['estimated_costs'] submit_date = data['submit_date'] status = 'pending' new_row = Expenses(name, email, category, description, link, estimated_costs, status, submit_date) db.session.add(new_row) db.session.commit() id = Expenses.query.order_by(Expenses.id.desc()).first().id response = { 'id': id, 'name': name, 'email': email, 'category': category, 'description': description, 'link': link, 'estimated_costs': estimated_costs, 'submit_date': data['submit_date'], 'status': status, 'decision_date': "" } return (jsonify(response), 201)
def post(): try: data = json.loads(request.data) if not data or not 'name' in data: abort(404) database = CreateDB(hostname='mysqlserver') db.create_all() coordinate = google_coordinates.address_to_cordinate(data['address'] + data['city'] + data['state'] + data) new_location = Location_API(data['name'], data['email'], data['category'], data['description'], data['link'], data['estimated_costs'], data['submit_date']) db.session.add(new_expense) db.session.commit() added_expense = { 'id': new_expense.id, 'name': new_expense.name, 'email': new_expense.email, 'category': new_expense.category, 'description': new_expense.description, 'link': new_expense.link, 'estimated_costs': new_expense.estimated_costs, 'submit_date': new_expense.submit_date, 'status': new_expense.status, 'decision_date': new_expense.decision_date } return json.dumps(added_expense), 201 except IntegrityError: return json.dumps({'status': False})
def post(): try: data = json.loads(request.data) if not data or not 'city' in data: abort(404) database = CreateDB(hostname='localhost') db.create_all() coordinate = google_coordinates.address_to_cordinate(data['address'] + data['city'] + data['state'] + data['zip']) lat = str(coordinate['lat']) lng = str(coordinate['lng']) new_location = Location_API(data['name'], data['address'], data['city'], data['state'], data['zip'], lat, lng) db.session.add(new_location) db.session.commit() added_location = { 'id': new_location.id, 'name': new_location.name, 'address': new_location.address, 'city': new_location.city, 'state': new_location.state, 'zip': new_location.zip, 'coordinate': { 'lat': new_location.lat, 'lng': new_location.lng } } return json.dumps(added_location), 201 except IntegrityError: return json.dumps({'status': False})
def createDatabase(): HOSTNAME = 'localhost' try: HOSTNAME = request.args['hostname'] except: pass database = CreateDB(hostname=HOSTNAME) return json.dumps({'status': True})
def insert_user(): json_data = json.loads(request.data) print json_data x = json_data['address'] x = x.replace(' ', '+') y = json_data['city'] y = y.replace(' ', '+') z = json_data['state'] a = str(json_data['zip']) string_for_google = x + '+' + y + '+' + z + '+' + a apidata = json.load( urllib2.urlopen( 'http://maps.google.com/maps/api/geocode/json?address=%s&sensor=False' % (string_for_google))) data = apidata['results'][0] geometry_data = data['geometry'] location_data = geometry_data['location'] latitude = location_data['lat'] longitude = location_data['lng'] database = CreateDB(hostname='') db.create_all() try: location = Location(json_data['name'], json_data['address'], json_data['city'], json_data['state'], json_data['zip'], latitude, longitude) db.session.add(location) db.session.commit() user_id = location.id return json.dumps({ 'id': str(location.id), 'name': location.name, 'address': location.address, 'city': location.city, 'state': location.state, 'zip': location.zip, 'coordinate': { 'lat': location.lat, 'lng': location.lng } }), 201 except IntegrityError: return json.dumps({'status': False})
def post_data(): try: data = json.loads(request.data) if not data or not 'email' in data: abort(404) database = CreateDB(hostname = 'localhost') db.create() user = User(data['name'], data['email'], data['category'], data['description'], data['link'], data['estimated_costs'], data['submit_date']) db.session.add(expense) db.session.commit() added_expense = {'id': user.id, 'name': user.name, 'email': user.email, 'category': user.category, 'description': user.description, 'link': user.link, 'estimated_costs': user.estimated_costs, 'submit_date': user.submit_date, 'status': user.status, 'decision_date': user.decision_date} return json.dumps(added_expense), 201 except IntegrityError: return json.dumps({'status':False})
def index(): database = CreateDB(hostname = 'localhost') db.create_all() return 'CMPE 273 Assignment 1 : Expense management system using Python Flask\n'
#--------DELETE elif request.method == 'DELETE': try: if int(shard_id) % 2 == 1: order_d = expense_5.query.filter_by(id=order_id).first() if order_d is not None: db.session.delete(order_d) db.session.commit() return json.dumps({'status': True}), 204 else: return json.dumps({'staus': False}), 404 else: order_d = expense_6.query.filter_by(id=order_id).first() if order_d is not None: db.session.delete(order_d) db.session.commit() return json.dumps({'status': True}), 204 else: return json.dumps({'staus': False}), 404 except IntegrityError: return json.dumps({'status': False}) #------------------------------------------------------------------------------------- #----run app service---- if __name__ == "__main__": HOSTNAME = 'mysqlserver' database = CreateDB(hostname=HOSTNAME) app.run(host='0.0.0.0', port=5002, debug=True)
def createDatabase(): database = CreateDB(hostname='mysqlserver') db.create_all() print("Database and table created")
def createDatabase(): HOSTNAME = 'mysqlserver' database = CreateDB(hostname=HOSTNAME) return json.dumps({'status': True})
from sklearn import preprocessing from sklearn.linear_model import LogisticRegression from sklearn.cross_validation import train_test_split from model import CreateDB import config from config import GetConfigDataHarshit as config_data #import simplejson as json from sqlalchemy.exc import IntegrityError import os from flask import request #initate flask app; app = Flask(__name__) app.config.from_object(config) CreateDB() db.create_all() min_max_scaler = preprocessing.MinMaxScaler(feature_range=(-1,1)) df=pd.read_csv('drugdata.csv', header=0) input_columns = ['AGE','GENDER','RACE','STFIPS'] output_columns_alc = ["ALCFLG"] output_columns_mar = ["MARFLG"] output_columns_cok = ["COKEFLG"] X = df[input_columns].values X = np.array(X) X = min_max_scaler.fit_transform(X)
def reset(): database = CreateDB() create_tables() setup_db() return redirect(url_for('index'))
def create_database(): CreateDB() print("Database created") return json.dumps({'status': 'True'})
def expenses(): CreateDB() try: if request.method == 'POST': json1 = request.get_json(force=True) name = json1['name'] email = json1['email'] category = json1['category'] description = json1['description'] link = json1['link'] estimated_costs = json1['estimated_costs'] submit_date = json1['submit_date'] order = Orders(name, email, category, description, link, estimated_costs, submit_date, 'PENDING', '') try: db.session.add(order) #db.session.execute() db.session.flush db.session.commit() except Exception as e: db.session.rollback() return jsonify({"Session message": e.message}) jsonString = { "id": order.id, "name": order.customerName, "email": order.customerEmail, "category": order.category, "description": order.description, "link": order.link, "estimated_costs": order.estimatedCost, "submit_date": order.submitDate, "status": order.status, "decision_date": "" } response = Response(response=json.dumps(jsonString), status=201, \ mimetype="application/json") return response else: orders = Orders.query.all() if None != orders: orders_dict = {} for order in orders: orders_dict[order.id] = { "id": order.id, "name": order.customerName, "email": order.customerEmail, "category": order.category, "description": order.description, "link": order.link, "estimated_costs": order.estimatedCost, "submit_date": order.submitDate, "status": order.status, "decision_date": "" } return json.dumps(orders_dict), 200 else: return jsonify({"message": "no row found"}), 404 except Exception as e: return jsonify({"message": e.message})
def createDatabase(): HOSTNAME = 'localhost' database = CreateDB() return json.dumps({'status': True})