-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
58 lines (44 loc) · 1.61 KB
/
app.py
File metadata and controls
58 lines (44 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import os
from flask import Flask, session, redirect, url_for, request, abort, jsonify
from flask_sqlalchemy import SQLAlchemy
from mobync import Mobync
from examples.relational_db_example.implementation import Implementation
app = Flask(__name__)
app.config.from_object(os.environ['APP_SETTINGS'])
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
implementation = Implementation()
sync = Mobync(implementation)
@app.route('/sync', methods=['POST'])
def sync():
data = request.get_json()
if sync.is_valid(data):
resp = sync.apply(data)
return jsonify(resp)
else:
abort(400, sync.error_message)
def connect_db():
try:
connection = psycopg2.connect(user="sysadmin",
password="pynative@#29",
host="127.0.0.1",
port="5432",
database="postgres_db")
cursor = connection.cursor()
# Print PostgreSQL Connection properties
print(connection.get_dsn_parameters(), "\n")
# Print PostgreSQL version
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record, "\n")
except (Exception, psycopg2.Error) as error:
print("Error while connecting to PostgreSQL", error)
finally:
# closing database connection.
if (connection):
cursor.close()
connection.close()
print("PostgreSQL connection is closed")
if __name__ == '__main__':
app.run()
connect_db()