def crowd_detection_video(): payload = request.get_json() status, message = ImageView(payload['video_string']).process_image() if status == 0: response = ({'Error': message}, http.HTTPStatus.CONFLICT) else: filepath = './app/images/' ob = ObjectDetection(filepath) person_count = max(ob.driver()) status = DBHandler().insert_value( 'heatmap', [str(payload['lat']), str(payload['long']), str(person_count)]) if person_count <= 3: DBHandler().decrement_token(payload['user']) else: DBHandler().increment_token(payload['user']) if status: response = ({ 'Person Count': str(person_count) }, http.HTTPStatus.OK) else: response = ({ 'Message': 'Could not update Database' }, http.HTTPStatus.CONFLICT) for file in os.listdir(filepath): if file.endswith('.jpg'): os.remove(filepath + file) return response
def crowd_detection(): payload = request.get_json() image_string = payload['image'] randint = random.randint(100000, 999999) filename = 'app/images/tmpImage' + str(randint) + '.jpg' response = ({'Message': 'Processing'}, http.HTTPStatus.OK) try: with open(filename, "wb") as fh: fh.write(base64.decodebytes(bytes(image_string, 'utf-8'))) ob = ObjectDetection(filename[:filename.rfind('/')]) person_count = max(ob.driver()) status = DBHandler().insert_value( 'heatmap', [str(payload['lat']), str(payload['long']), str(person_count)]) if person_count <= 3: DBHandler().decrement_token(payload['user']) else: DBHandler().increment_token(payload['user']) print("here") if status: response = ({ 'Person Count': str(person_count) }, http.HTTPStatus.OK) else: response = ({ 'Message': 'Could not update Database' }, http.HTTPStatus.CONFLICT) os.remove(filename) except Exception as e: os.remove(filename) response = ({'Error': 'Error'}, http.HTTPStatus.CONFLICT) return response
def get_heatmap(): status, data = DBHandler().get_heatmap() if status == 0: response = ({'Error': data}, http.HTTPStatus.CONFLICT) else: response = (json.dumps(data), http.HTTPStatus.OK) return response
def insert_data(): payload = request.get_json() status = DBHandler().insert_value(payload['table_name'], payload['parameters']) if status == 0: response = ({'Error': 'Could Not Insert Data'}, http.HTTPStatus.CONFLICT) else: response = ({'Message': 'Data Inserted Successfully'}, http.HTTPStatus.OK) return response
def decrement_token(): payload = request.get_json() status = DBHandler().decrement_token(payload['user']) if status == 0: response = ({'Error': 'Cannot Decrement Token'}, http.HTTPStatus.CONFLICT) else: response = ({'Message': 'Token Decremented Successfully'}, http.HTTPStatus.OK) return response
def register(): payload = request.get_json() status = DBHandler().register(payload['user'], payload['name'], payload['password']) if status == 0: response = ({'Error': 'Could Not Register'}, http.HTTPStatus.CONFLICT) else: response = ({'Message': 'Registered Successfully'}, http.HTTPStatus.CREATED) return response
def create_table(): payload = request.get_json() status = DBHandler().create_table(payload['table_name'], payload['parameters']) if status == 0: response = ({'Error': 'Could Not Create Table'}, http.HTTPStatus.CONFLICT) else: response = ({'Message': 'Table Created Successfully'}, http.HTTPStatus.CREATED) return response
def update_heatmap_state(): payload = request.get_json() status, data = DBHandler().update_heatmap_state(payload['lat'], payload['long'], payload['weight']) if data: response = ({'Message': data}, http.HTTPStatus.OK) else: response = ({'Error': data}, http.HTTPStatus.CONFLICT) return response
def login(): payload = request.get_json() status, result = DBHandler().login(payload['user'], payload['password']) if status == 0: response = ({'Error': 'Could Not Fetch Data'}, http.HTTPStatus.CONFLICT) elif status == 5: response = ({'Error': 'User Not Present'}, http.HTTPStatus.NO_CONTENT) else: response = ({'Name': result[2], 'Token': result[1]}, http.HTTPStatus.OK) return response
def crowd_detection(): payload = request.get_json() image_string = payload['image'] randint = random.randint(100000, 999999) filename = './app/images/tmpImage' + str(randint) + '.jpg' response = ({'Message': 'Processing'}, http.HTTPStatus.OK) try: with open(filename, "wb") as fh: fh.write(base64.decodebytes(bytes(image_string, 'utf-8'))) print(DBHandler().insert_value('heatmap', [str(payload['lat']), str(payload['long']), str(random.randint(1, 11))])) except Exception as e: response = ({'Error': 'Error'}, http.HTTPStatus.OK) return response
def send_otp_mail(self, receivers): otp = str(random.randint(1000, 9999)) body = "Your OTP for Crowd Safe is " + otp subject = 'OTP for Crowd Safe' status, res = DBHandler().get_phone(receivers[0]) if res: return "Email Already Exists" try: self.send_mail(body, subject, receivers) except Exception as e: otp = None return otp return self.encrypt_string(otp)
status = DBHandler().decrement_token(payload['user']) if status == 0: response = ({ 'Error': 'Cannot Decrement Token' }, http.HTTPStatus.CONFLICT) else: response = ({ 'Message': 'Token Decremented Successfully' }, http.HTTPStatus.OK) return response @app.route("/state_data", methods=['GET']) def state_data(): status, data = WebScraper().get_statewise_data() if status == 0: response = ({'Error': data}, http.HTTPStatus.CONFLICT) else: response = (json.dumps(data), http.HTTPStatus.OK) return response if __name__ == '__main__': table_name = 'user' parameters = [ 'phone VARCHAR(10) PRIMARY KEY', 'name TEXT NOT NULL', 'password VARCAHR(256) NOT NULL', 'token INT' ] DBHandler().create_table(table_name, parameters) app.run()
def set_database(): obj = DBHandler() obj.set_database() return "True"
def delete(): obj = DBHandler() obj.execute_query('DELETE FROM user') return "True"
def delete(): obj = DBHandler() obj.execute_query('DROP TABLE heatmap') return "True"