--- /dev/null +++ b/smsreports.py @@ -1 +1,50 @@ +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)