Commit 20124b87 authored by Pamal-Ranasinghe's avatar Pamal-Ranasinghe

mongodb connection implemented

parent fb9cb14a
#import flask module #import flask module
from flask import Flask from flask import Flask, request, jsonify
from flask_restful import Api from flask_restful import Api
from resources.routes import initialize_routes 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__) app = Flask(__name__)
api = Api(app) 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 #Test route
@app.route('/') @app.route('/')
def hello_world(): 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): ...@@ -41,7 +41,7 @@ class SpeechExtraction(Resource):
} }
#remove the coverted.wav for get more space in the server #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 the json object which is having converted speech
return json.loads(json.dumps(value)), 200 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