Commit 7f6d8c3349b2779154320cdb832f656151121fa1

  • avatar
  • arvind
  • Sat Jan 25 20:21:21 IST 2014
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 +++++++++++++++++++++++++++++++++++++++++++++++++
  • Diff rendering mode:
  • inline
  • side by side

smsreports.py

1import flask
2from flask.ext.sqlalchemy import SQLAlchemy
3import config
4from datetime import datetime
5
6app = flask.Flask(__name__)
7app.config['SQLALCHEMY_DATABASE_URI'] = config.URI
8db = SQLAlchemy(app)
9
10
11class smsReport(db.Model):
12 id = db.Column(db.Integer, primary_key=True)
13 jobID = db.Column(db.String(9))
14 number = db.Column(db.String(10))
15 status = db.Column(db.Integer)
16 doneTime = db.Column(db.DateTime)
17 message = db.Column(db.String(160))
18
19 def __init__(self, jobID, number, status, doneTime, message):
20 self.jobID = jobID
21 self.number = number
22 self.status = status
23 self.doneTime = doneTime
24 self.message = message
25
26@app.before_first_request
27def create_db():
28 db.create_all()
29
30@app.route('/', methods=['GET'])
31def index():
32 return flask.render_template('index.html')
33
34@app.route('/report', methods=['GET'])
35def report():
36 jobID = flask.request.args['jobno']
37 number = flask.request.args['mobilenumber']
38 status = flask.request.args['status']
39 doneTime = datetime.strptime(flask.request.args["doneTime"], "'%m/%d/%Y %I:%M:%S%p'")
40 message = flask.request.args["messagepart"]
41
42 report = smsReport(jobID, number, status, doneTime, message)
43 db.session.add(report)
44 db.session.commit()
45 response = flask.make_response()
46 return response
47
48if __name__ == "__main__":
49 app.run("localhost",5000, debug=True)