def deleteavailableservices(): # http://127.0.0.1:53000/addavailableservices print("inside 2 deleteavailableservices") data = request.get_json() print("deleteavailableservices input : " + json.dumps(data)) print("deleteavailableservices input id: " + str(data['id'])) try: AvailableServices.query.filter_by(id=data['id']).delete() db.session.commit() except Exception: print("No AvailableServices record in DB") pass print("Other exception") response = { "status": False, "description": "unknown error deleting AvailableServices info" } return app.response_class(json.dumps(response), content_type='application/json') finally: print("Deleted the AvailableServices data from DB") response = ({ "status": True, "description": "Deleted the AvailableServices data from DB" }) return app.response_class(json.dumps(response), content_type='application/json')
def listavailableservices(): # http://127.0.0.1:53000/listavailableservices print("inside listavailableservices") available_services_list = db.session.query(AvailableServices) temp_list = [] for temp_available_services_list in available_services_list: temp_asl = { "id": temp_available_services_list.id, "vehicle_type_id": temp_available_services_list.vehicle_type_id, "service_type_id": temp_available_services_list.service_type_id, "vehicle_condition_id": temp_available_services_list.vehicle_condition_id, "base_price": temp_available_services_list.base_price } temp_list.append(temp_asl) print("base_price:" + str(temp_available_services_list.base_price)) print("id:" + str(temp_available_services_list.id)) print("service_type_id:" + str(temp_available_services_list.service_type_id)) print("vehicle_condition_id:" + str(temp_available_services_list.vehicle_condition_id)) print("base_price:" + str(temp_available_services_list.base_price)) print("--------------------") return app.response_class(json.dumps(temp_list), content_type='application/json')
def listspecialservices(): # http://127.0.0.1:53000/listspecialservices print("inside listspecialservices") special_services_list = db.session.query(SpecialServices) temp_list = [] for temp_special_service_list in special_services_list: temp_list.append({ "id": temp_special_service_list.id, "vehicle_type_id": temp_special_service_list.vehicle_type_id, "name": temp_special_service_list.name, "question": temp_special_service_list.question, "price": temp_special_service_list.price }) print("id" + str(temp_special_service_list.id)) print("vehicle_type_id" + str(temp_special_service_list.vehicle_type_id)) print("price" + str(temp_special_service_list.price)) print("question" + str(temp_special_service_list.question)) print("name" + str(temp_special_service_list.name)) print("----------------------") return app.response_class(json.dumps(temp_list), content_type='application/json')
def editavailableserviceimages(): # http://127.0.0.1:53000/addavailableservices print("inside 2 editavailableserviceimages") data = request.get_json() print("editavailableserviceimages input vehicleTypeId: " + str(data['vehicleTypeId'])) print("editavailableserviceimages input serviceTypeId: " + str(data['serviceTypeId'])) if (data['BCImage'] and (len(data['BCImage']) > 0)): tmpimglocalfilename = tmplocaldir+ \ "/v"+str(data['vehicleTypeId'])+ \ "_s"+str(data['serviceTypeId'])+ \ "_before.png" if os.path.isfile(tmpimglocalfilename): oldtmpimglocalfilename = tmplocaldir+ \ "/old_v"+str(data['vehicleTypeId'])+ \ "_s"+str(data['serviceTypeId'])+ \ "_before.png" if os.path.isfile(oldtmpimglocalfilename): os.remove(oldtmpimglocalfilename) print("deleted old file:" + oldtmpimglocalfilename) # os.rename(tmpimglocalfilename, oldtmpimglocalfilename) print("rename file:" + oldtmpimglocalfilename) fh = open(tmpimglocalfilename, "wb") imgData = base64.b64decode(data['BCImage']) fh.write(imgData) #fh.close fh.close() print("before tmpimglocalfilename:" + tmpimglocalfilename) if (data['ACImage'] and (len(data['ACImage']) > 0)): tmpimglocalfilename = tmplocaldir+ \ "/v"+str(data['vehicleTypeId'])+ \ "_s"+str(data['serviceTypeId'])+ \ "_after.png" if os.path.isfile(tmpimglocalfilename): oldtmpimglocalfilename = tmplocaldir+ \ "/old_v"+str(data['vehicleTypeId'])+ \ "_s"+str(data['serviceTypeId'])+ \ "_after.png" if os.path.isfile(oldtmpimglocalfilename): os.remove(oldtmpimglocalfilename) print("deleted old file:" + oldtmpimglocalfilename) # os.rename(tmpimglocalfilename, oldtmpimglocalfilename) print("rename file:" + oldtmpimglocalfilename) fh = open(tmpimglocalfilename, "wb") imgData = base64.b64decode(data['ACImage']) fh.write(imgData) #fh.close fh.close() print("after tmpimglocalfilename:" + tmpimglocalfilename) response2 = ({"status": True, "description": "Image successfully posted"}) return app.response_class(json.dumps(response2), content_type='application/json')
def downloadGCImages(): # http://127.0.0.1:53000/downloadGCImages print("inside downloadGCImages2") imagelist = [] DOGS_BUCKET = "rajpics" CATS_BUCKET = "rajpics" # Listing objects uri = boto.storage_uri(DOGS_BUCKET, GOOGLE_STORAGE) for obj in uri.get_bucket(): print('%s://%s/%s' % (uri.scheme, uri.bucket_name, obj.name)) # print(' "%s"' % obj.get_contents_as_string()) # , "image":obj.get_contents_as_string() imagelist.append({"bucket_name": uri.bucket_name, "name": obj.name}) print("image added to json list") src_uri = boto.storage_uri(DOGS_BUCKET + '/' + obj.name, GOOGLE_STORAGE) # Create a file-like object for holding the object contents. object_contents = io.BytesIO() # object_contents = obj.get_contents_as_string() # The unintuitively-named get_file() doesn't return the object # contents; instead, it actually writes the contents to # object_contents. src_uri.get_key().get_file(object_contents) print("after get file") local_dst_uri = boto.storage_uri(os.path.join(tmplocaldir, obj.name), LOCAL_FILE) bucket_dst_uri = boto.storage_uri(CATS_BUCKET + '/' + obj.name, GOOGLE_STORAGE) print("before writing to local file") # for dst_uri in (local_dst_uri, bucket_dst_uri): # print("before seek") # object_contents.seek(0) # print("after seek") # dst_uri.new_key().set_contents_from_file(object_contents) # print("after write") print("before seek") object_contents.seek(0) print("after seek") local_dst_uri.new_key().set_contents_from_file(object_contents) print("after write") object_contents.close() print("Images written to dir:" + tmplocaldir) return app.response_class(json.dumps(imagelist), content_type='application/json')
def listvehiclecondition(): # http://127.0.0.1:53000/listvehiclecondition print("inside listvehiclecondition") vehicle_condition_list = [] vehiclecondition = db.session.query(VehicleCondition) for lvehiclecondition in vehiclecondition: vehicle_condition_list.append({ "id":lvehiclecondition.id, "condition":lvehiclecondition.condition }) return app.response_class(json.dumps(vehicle_condition_list), content_type='application/json')
def listGCBucketNames(): # http://127.0.0.1:53000/listGCBucketNames bucketlist = [] uri = boto.storage_uri('', GOOGLE_STORAGE) header_values = {"x-goog-project-id": tmpproject_num} # If the default project is defined, call get_all_buckets() without arguments. for bucket in uri.get_all_buckets(headers=header_values): print("bucket name:" + bucket.name) bucketlist.append({"bucket_name": bucket.name}) return app.response_class(json.dumps(bucketlist), content_type='application/json')
def listlocationtype(): # http://127.0.0.1:53000/listservicetypes print("inside listlocationtype") location_list = [] locationtype = db.session.query(Location) for llocationtype in locationtype: location_list.append({ "id":llocationtype.id, "location":llocationtype.location }) return app.response_class(json.dumps(location_list), content_type='application/json')
def listvehicletypes(): # http://127.0.0.1:53000/listservicetypes print("inside listvehicletypes") vehicle_type_list = [] vehicletype = db.session.query(VehicleType) for lvehicletype in vehicletype: vehicle_type_list.append({ "id": lvehicletype.id, "type": lvehicletype.type, "display_text": lvehicletype.display_text }) return app.response_class(json.dumps(vehicle_type_list), content_type='application/json')
def listzipcode(): # http://127.0.0.1:53000/listzipcode print("inside listzipcode") zipcode_list = [] zipcode = db.session.query(ZipCode) for lzipCode in zipcode: zipcode_list.append({ "id": lzipCode.id, "zip_code": lzipCode.zip_code, "price_increase": lzipCode.price_increase }) return app.response_class(json.dumps(zipcode_list), content_type='application/json')
def listservicetypes(): # http://127.0.0.1:53000/listservicetypes print("inside listservicetypes") service_type_list = [] servicetype = db.session.query(ServiceType) for lservicetype in servicetype: service_type_list.append({ "id": lservicetype.id, "name": lservicetype.name, "display_name": lservicetype.display_name, "description": lservicetype.description }) return app.response_class(json.dumps(service_type_list), content_type='application/json')
def addvehicletype(): # http://127.0.0.1:53000/addvehicletype print("inside addvehicletype") data = request.get_json() or request.form print("response : " + json.dumps(data)) print("response serviceName: " + data['vehicleType']) vehicleType = VehicleType(data['vehicleType'], data['vdisplayText']) db.session.add(vehicleType) db.session.commit() flash('New entry was successfully posted') response2 = ({ "status": True, "description": "New entry was successfully posted" }) return app.response_class(json.dumps(response2), content_type='application/json')
def getGoogleCloudInstanceList(): # http://127.0.0.1:53000/getGoogleCloudInstanceList # gcs_oauth2_boto_plugin.SetFallbackClientIdAndSecret(tmpclientid, tmpclientsecret) imagelist = [] credentials = GoogleCredentials.get_application_default() service = build('compute', 'v1', credentials=credentials) PROJECT = 'bamboo-machine-422' ZONE = 'us-central1-a' request = service.instances().list(project=tmpprojectid, zone=ZONE) response = request.execute() print("Instance list:" + json.dumps(response)) return app.response_class(json.dumps(response), content_type='application/json')
def addvehiclecondition(): # http://127.0.0.1:53000/addvehiclecondition print("inside addvehiclecondition") data = request.get_json() or request.form print("response : "+ json.dumps(data)) print("response vehiclecondition: "+ data['condition']) vehiclecondition = VehicleCondition(condition=data['condition']) db.session.add(vehiclecondition) db.session.commit() flash('New entry was successfully posted') response2 = ( { "status": True, "description": "New entry was successfully posted" } ) return app.response_class(json.dumps(response2), content_type='application/json')
def addzipcode(): # http://127.0.0.1:53000/addzipcode print("inside addzipcode") data = request.get_json() or request.form print("request : " + json.dumps(data)) print("request addzipcode: " + data['zipcode']) tmp_price_inc = int(data['priceIncrease']) print("tmp_price_inc: " + data['priceIncrease']) zipcode = ZipCode(zip_code=data['zipcode'], price_increase=tmp_price_inc) db.session.add(zipcode) db.session.commit() flash('New entry was successfully posted') response2 = ({ "status": True, "description": "New entry was successfully posted" }) return app.response_class(json.dumps(response2), content_type='application/json')
def uploadImagestoGC(): # http://127.0.0.1:53000/downloadGCImages print("inside uploadImagestoGC") # print("image :"+request.form(["imageid"])) imagelist = [] DOGS_BUCKET = "rajpics" CATS_BUCKET = "rajpics" # local_dst_uri = boto.storage_uri( # request.form(["imageid"]), LOCAL_FILE) bucket_dst_uri = boto.storage_uri( CATS_BUCKET + '/' + request.form.get("imageid"), GOOGLE_STORAGE) print("image :" + request.form.get("imageid")) print("Images written to google cloud") return app.response_class(json.dumps(imagelist), content_type='application/json')
def listavailableserviceimages(): # http://127.0.0.1:53000/listavailableserviceimages print("inside listavailableserviceimages") temp_list = [] for temp_file in os.listdir(tmplocaldir): if temp_file.endswith("_before.png"): temp_asl = {} temp_file_words = temp_file.split("_") print("before_clean_image temp_file:" + temp_file) print("0:" + str(temp_file_words[0])) print("1:" + str(temp_file_words[1])) print("2:" + str(temp_file_words[2])) temp_asl = { "vehicle_type_id": temp_file_words[0][1:], "service_type_id": temp_file_words[1][1:] } temp_asl['before_clean_image'] = tmplocaldir + "/" + temp_file tmpimglocalfilename = tmplocaldir+ \ "/v"+str(temp_file_words[0][1:])+ \ "_s"+str(temp_file_words[1][1:])+ \ "_after.png" # "_vc"+str(temp_available_services_list.vehicle_condition_id)+ \ if os.path.isfile(tmpimglocalfilename) and os.access( tmpimglocalfilename, os.R_OK): temp_asl['after_clean_image'] = tmpimglocalfilename print("after_clean_image:" + temp_asl['after_clean_image']) else: temp_asl['after_clean_image'] = "" temp_list.append(temp_asl) return app.response_class(json.dumps(temp_list), content_type='application/json')
def editservicetypes(): # http://127.0.0.1:53000/editservicetypes print("inside 2 editservicetypes") data = request.get_json() print("editservicetypes input : " + json.dumps(data)) print("editservicetypes input serviceTypeId: " + str(data['serviceName'])) recexists = 0 db_last_apicall_date = "" l_serviceType = db.session.query(ServiceType).filter_by(id=data['id']) response2 = "" if (data['id']): try: record = l_serviceType.one() recexists = 1 except Exception: print("No service type record in DB") pass finally: print("servicetypes data exists in DB") if (recexists == 1): print("existing servicetypes data") print("id:" + str(record.id)) print("service name:" + str(record.name)) print("sdisplay_text:" + str(record.display_name)) if (recexists == 1) and (l_serviceType.count() > 0): print("trying to update new values") record.name = data['serviceName'] record.display_name = data['sDisplayName'] record.description = data['sDescription'] if (recexists == 0): servicetypes = ServiceType(data['serviceName'], data['sDisplayName'], data['sDescription']) db.session.add(servicetypes) exception_info = 0 try: db.session.commit() except exc.IntegrityError as err: print("exception") db.session.rollback() if "Duplicate entry" in str(err): print("Duplicate exception") exception_info = 1 response = { "status": False, "description": "IntegrityError error, ServiceType already exists" } return app.response_class(json.dumps(response), content_type='application/json') else: print("Other exception") response = { "status": False, "description": "unknown error adding/updating ServiceType info" } return app.response_class(json.dumps(response), content_type='application/json') finally: print("finally") if (exception_info > 0): response2 = ({ "status": False, "description": "Exception occured while processing record" }) if (exception_info == 0): response2 = ({ "status": True, "description": "New entry was successfully posted" }) return app.response_class(json.dumps(response2), content_type='application/json')
def editzipcode(): # http://127.0.0.1:53000/editzipcode print("inside 2 editzipcode") data = request.get_json() print("editzipcode input : " + json.dumps(data)) print("editzipcode input serviceTypeId: " + str(data['zipcode'])) recexists = 0 l_zipcode = db.session.query(ZipCode).filter_by(id=data['id']) response2 = "" if (data['id']): try: record = l_zipcode.one() recexists = 1 except Exception as err: print("No Zipcode record in DB" + str(err)) pass finally: print("zipcode data exists in DB") if (recexists == 1): print("existing zipcode data") print("id:" + str(record.id)) print("zip_code:" + str(record.zip_code)) print("price_increase:" + str(record.price_increase)) if (recexists == 1) and (l_zipcode.count() > 0): print("trying to update new values") record.zip_code = data['zipcode'] record.price_increase = data['priceIncrease'] if (recexists == 0): zipcode = ZipCode(zip_code=data['zipcode'], price_increase=data['priceIncrease']) db.session.add(zipcode) exceptio_info = 0 try: db.session.commit() except exc.IntegrityError as err: print("exception") db.session.rollback() if "Duplicate entry" in str(err): print("Duplicate exception") exceptio_info = 1 response = { "status": False, "description": "IntegrityError error,zipcode already exists" } return app.response_class(json.dumps(response), content_type='application/json') else: print("Other exception") response = { "status": False, "description": "unknown error adding/updating zipcode info" } return app.response_class(json.dumps(response), content_type='application/json') finally: print("finally") if (exceptio_info > 0): response2 = ({ "status": False, "description": "Exception occured while processing record" }) if (exceptio_info == 0): response2 = ({ "status": True, "description": "New entry was successfully posted" }) return app.response_class(json.dumps(response2), content_type='application/json')
def editavailableservices(): # http://127.0.0.1:53000/addavailableservices print("inside 2 editavailableservices") data = request.get_json() print("editavailableservices input vehicleTypeId: " + str(data['vehicleTypeId'])) recexists = 0 db_last_apicall_date = "" l_avail_serv = db.session.query(AvailableServices).filter_by( vehicle_type_id=data['vehicleTypeId'], service_type_id=data['serviceTypeId'], vehicle_condition_id=data['vehicleConditionId']) response2 = "" try: record = l_avail_serv.one() recexists = 1 except Exception: print("No AvailableServices record in DB") pass finally: print("AvailableServices data exists in DB") if (recexists == 1): print("existing AvailableServices data") print("id:" + str(record.id)) print("vehicle_type_id:" + str(record.vehicle_type_id)) print("service_type_id:" + str(record.service_type_id)) print("vehicle_condition_id:" + str(record.vehicle_condition_id)) print("base_price:" + str(record.base_price)) print("tmplocaldir:" + tmplocaldir) print("--------------------------") if (recexists == 1) and (l_avail_serv.count() > 0): print("trying to update new values") print("basePrice:" + data['basePrice']) record.base_price = data['basePrice'] if (recexists == 0): availableservices = AvailableServices(data['vehicleTypeId'], data['serviceTypeId'], data['vehicleConditionId'], data['basePrice']) db.session.add(availableservices) exceptio_info = 0 try: db.session.commit() except exc.IntegrityError as err: print("exception") db.session.rollback() if "Duplicate entry" in str(err): print("Duplicate exception") exceptio_info = 1 response = { "status": False, "description": "IntegrityError error, AvailableServices already exists" } return app.response_class(json.dumps(response), content_type='application/json') else: print("Other exception") response = { "status": False, "description": "unknown error adding/updating AvailableServices info" } return app.response_class(json.dumps(response), content_type='application/json') finally: print("finally") if (exceptio_info > 0): response2 = ({ "status": False, "description": "Exception occured while processing record" }) if (exceptio_info == 0): response2 = ({ "status": True, "description": "New entry was successfully posted" }) return app.response_class(json.dumps(response2), content_type='application/json')
def editspecialservices(): # http://127.0.0.1:53000/editspecialservices print("inside editspecialservices") data = request.get_json() print("editspecialservices input : " + json.dumps(data)) print("editspecialservices input vehicleTypeId: " + str(data['vehicleTypeId'])) recexists = 0 db_last_apicall_date = "" l_special_service = db.session.query(SpecialServices).filter_by( id=data['ssId']) response2 = "" try: record = l_special_service.one() recexists = 1 except Exception: print("No Special Services record in DB") pass finally: print("specialservices data exists in DB") if (recexists == 1): print("existing specialservices data") print("id:" + str(record.id)) print("vehicle_type_id:" + str(record.vehicle_type_id)) print("name:" + str(record.name)) print("question:" + str(record.question)) print("price:" + str(record.price)) if (recexists == 1) and (l_special_service.count() > 0): print("trying to update new values") record.price = data['QPrice'] record.question = data['Question'] if (recexists == 0): specialservices = SpecialServices(data['vehicleTypeId'], data['QName'], data['Question'], data['QPrice']) db.session.add(specialservices) exceptio_info = 0 try: db.session.commit() except exc.IntegrityError as err: print("exception") db.session.rollback() if "Duplicate entry" in str(err): print("Duplicate exception") exceptio_info = 1 response = { "status": False, "description": "IntegrityError error, AvailableServices already exists" } return app.response_class(json.dumps(response), content_type='application/json') else: print("Other exception") response = { "status": False, "description": "unknown error adding/updating AvailableServices info" } return app.response_class(json.dumps(response), content_type='application/json') finally: print("finally") if (exceptio_info > 0): response2 = ({ "status": False, "description": "Exception occured while processing record" }) if (exceptio_info == 0): response2 = ({ "status": True, "description": "New entry was successfully posted" }) return app.response_class(json.dumps(response2), content_type='application/json')
def editvehiclecondition(): # http://127.0.0.1:53000/editvehiclecondition print("inside 2 editvehiclecondition") data = request.get_json() print("editvehiclecondition input : " + json.dumps(data)) print("editvehiclecondition input vehicleConditionId: " + str(data['vehicleCondition'])) recexists = 0 db_last_apicall_date = "" l_vehicleCondition = db.session.query(VehicleCondition).filter_by(id=data['id']) response2 = "" if (data['id']): try: record = l_avail_serv.one() recexists = 1 except Exception: print("No vehiclecondition record in DB") pass finally: print("vehiclecondition data exists in DB") if ( recexists == 1): print("existing vehicleCondition data") print("id:"+str(record.id)) print("vehicle_condition:"+str(record.condition)) if ( recexists == 1) and (l_vehicleCondition.count() > 0): print("trying to update new values") record.type = data['vehicleType'] record.display_text = data['vdisplayText'] if ( recexists == 0): vehiclecondition = VehicleCondition(condition=data['vehicleCondition']) db.session.add(vehiclecondition) exceptio_info=0 try: db.session.commit() except exc.IntegrityError as err: print("exception") db.session.rollback() if "Duplicate entry" in str(err): print("Duplicate exception") exceptio_info = 1 response = { "status" : False, "description" : "IntegrityError error, AvailableServices already exists" } return app.response_class(json.dumps(response), content_type='application/json') else: print("Other exception") response = { "status" : False, "description" : "unknown error adding/updating AvailableServices info" } return app.response_class(json.dumps(response), content_type='application/json') finally: print("finally") if ( exceptio_info>0): response2 = ( { "status": False, "description": "Exception occured while processing record" } ) if ( exceptio_info == 0): response2 = ( { "status": True, "description": "New entry was successfully posted" } ) return app.response_class(json.dumps(response2), content_type='application/json')