7f6d8c3 by Arvind at 2014-01-25 |
1 |
import flask |
|
2 |
from flask.ext.sqlalchemy import SQLAlchemy |
|
3 |
import config |
|
4 |
from datetime import datetime |
|
5 |
|
|
6 |
app = flask.Flask(__name__) |
|
7 |
app.config['SQLALCHEMY_DATABASE_URI'] = config.URI |
|
8 |
db = SQLAlchemy(app) |
|
9 |
|
|
10 |
|
|
11 |
class 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 |
|
27 |
def create_db(): |
|
28 |
db.create_all() |
|
29 |
|
|
30 |
@app.route('/', methods=['GET']) |
|
31 |
def index(): |
|
32 |
return flask.render_template('index.html') |
|
33 |
|
|
34 |
@app.route('/report', methods=['GET']) |
|
35 |
def 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 |
|
|
48 |
if __name__ == "__main__": |
|
49 |
app.run("localhost",5000, debug=True) |