From 7f6d8c3349b2779154320cdb832f656151121fa1 Mon Sep 17 00:00:00 2001 From: Arvind Date: Sat, 25 Jan 2014 20:21:21 +0530 Subject: [PATCH] SMS country provides dynamic reports and pushes it to a URL we specify. This is a flask-sqlalchemy app to get those reports, store it in a db, and a web interface to see the reports. --- smsreports.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 smsreports.py diff --git a/smsreports.py b/smsreports.py new file mode 100644 index 0000000..2932af6 --- /dev/null +++ b/smsreports.py @@ -0,0 +1,49 @@ +import flask +from flask.ext.sqlalchemy import SQLAlchemy +import config +from datetime import datetime + +app = flask.Flask(__name__) +app.config['SQLALCHEMY_DATABASE_URI'] = config.URI +db = SQLAlchemy(app) + + +class smsReport(db.Model): + id = db.Column(db.Integer, primary_key=True) + jobID = db.Column(db.String(9)) + number = db.Column(db.String(10)) + status = db.Column(db.Integer) + doneTime = db.Column(db.DateTime) + message = db.Column(db.String(160)) + + def __init__(self, jobID, number, status, doneTime, message): + self.jobID = jobID + self.number = number + self.status = status + self.doneTime = doneTime + self.message = message + +@app.before_first_request +def create_db(): + db.create_all() + +@app.route('/', methods=['GET']) +def index(): + return flask.render_template('index.html') + +@app.route('/report', methods=['GET']) +def report(): + jobID = flask.request.args['jobno'] + number = flask.request.args['mobilenumber'] + status = flask.request.args['status'] + doneTime = datetime.strptime(flask.request.args["doneTime"], "'%m/%d/%Y %I:%M:%S%p'") + message = flask.request.args["messagepart"] + + report = smsReport(jobID, number, status, doneTime, message) + db.session.add(report) + db.session.commit() + response = flask.make_response() + return response + +if __name__ == "__main__": + app.run("localhost",5000, debug=True) \ No newline at end of file -- 1.7.10.4