Commit 97ee6874 authored by Ranasinghe R.A.P.T's avatar Ranasinghe R.A.P.T

Merge branch 'feature/mongo-db-connection' into 'dev'

mongodb connection implemented

See merge request !3
parents fb9cb14a 20124b87
#import flask module
from flask import Flask
from flask import Flask, request, jsonify
from flask_restful import Api
from resources.routes import initialize_routes
from database.models import User
from database.db import initialize_db
from loguru import logger
import json
app = Flask(__name__)
api = Api(app)
app.config['MONGODB_SETTINGS'] = {
'db': 'rp_server_one',
'host': 'localhost',
'port': 27017
}
initialize_db(app)
# class User(db.Document):
# name = db.StringField()
# email = db.StringField()
# def to_json(self):
# return {"name": self.name,
# "email": self.email}
@app.route('/add', methods=['POST'])
def update_record():
record = request.get_json()
user = User(name=record['name'], email=record['email']).save()
# user.save()
logger.info("object", user)
logger.info("record is inserted")
return {"message" : "ok"}
#Test route
@app.route('/')
def hello_world():
......
from flask_mongoengine import MongoEngine
db = MongoEngine()
def initialize_db(app):
db.init_app(app)
\ No newline at end of file
from .db import db
class User(db.Document):
name = db.StringField()
email = db.StringField()
def to_json(self):
return {"name": self.name,
"email": self.email}
\ No newline at end of file
......@@ -41,7 +41,7 @@ class SpeechExtraction(Resource):
}
#remove the coverted.wav for get more space in the server
os.remove(os.path.join(os.getenv('CONVERTED_AUDIO_PATH'), os.getenv('CONVERTED_AUDIO_FILE_NAME')))
os.remove(os.path.join("D:/rp_server_one/assets/converted_wav", "converted.wav"))
#return the json object which is having converted speech
return json.loads(json.dumps(value)), 200
......
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