123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- #!/bin/env python
- from flask import Flask, request
- from flask_restful import Resource, Api
- from flask_sqlalchemy import SQLAlchemy
- app = Flask(__name__)
- app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+oursql://ibrweb:;gH8eE6vo@localhost/ibr'
- app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
- app.config['RESTFUL_JSON'] = { 'separators': ( ', ', ': '), 'indent': 2 }
- db = SQLAlchemy(app)
- class Candidate(db.Model):
- __tablename__ = 'candidate'
- __table_args__ = (
- db.Index('iStatus', 'status', 'ID'),
- db.Index('iCompanyStatusSubmittedOn', 'company', 'status', 'Submitted_On'),
- db.Index('iCompany', 'company', 'ID')
- )
- ID = db.Column(db.Integer, primary_key=True)
- company = db.Column(db.String(25), nullable=False, server_default=db.FetchedValue())
- passfail = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
- status = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
- First = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue())
- Middle = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue())
- Last = db.Column(db.String(90), nullable=False, index=True, server_default=db.FetchedValue())
- Aliases = db.Column(db.Text)
- SSN = db.Column(db.String(9), nullable=False, index=True, server_default=db.FetchedValue())
- SSNfound = db.Column(db.String(9), nullable=False, index=True, server_default=db.FetchedValue())
- DOB = db.Column(db.Date, nullable=False, server_default=db.FetchedValue())
- Phone = db.Column(db.String(25), nullable=False, server_default=db.FetchedValue())
- Address = db.Column(db.String(255), nullable=False, server_default=db.FetchedValue())
- City = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue())
- County = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue())
- State = db.Column(db.String(2), nullable=False, server_default=db.FetchedValue())
- ZipCode = db.Column(db.String(25), nullable=False, server_default=db.FetchedValue())
- PreviousAddresses = db.Column(db.Text)
- Comments = db.Column(db.Text)
- username = db.Column(db.String(25), nullable=False, server_default=db.FetchedValue())
- Submitter = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue())
- Submitter_Phone = db.Column(db.String(35), nullable=False, server_default=db.FetchedValue())
- Submitter_company = db.Column(db.String(25), nullable=False, server_default=db.FetchedValue())
- cost = db.Column(db.Float, nullable=False, server_default=db.FetchedValue())
- order_name = db.Column(db.String(25), nullable=False, index=True, server_default=db.FetchedValue())
- completed = db.Column(db.DateTime, nullable=False, index=True, server_default=db.FetchedValue())
- Submitted_On = db.Column(db.DateTime, nullable=False, index=True, server_default=db.FetchedValue())
- Gender = db.Column(db.String(1), nullable=False, server_default=db.FetchedValue())
- lastfilename = db.Column(db.String(90))
- TIN = db.Column(db.String(9), nullable=False, server_default=db.FetchedValue())
- business = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue())
- email = db.Column(db.String(75), nullable=False, server_default=db.FetchedValue())
- minimal = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
- failmail = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
- sendreport = db.Column(db.Integer, nullable=False, index=True, server_default=db.FetchedValue())
- clientpassthru = db.Column(db.String(50), nullable=False, server_default=db.FetchedValue())
- class Login(db.Model):
- __tablename__ = 'login'
- username = db.Column(db.String(25), primary_key=True, server_default=db.FetchedValue())
- password = db.Column(db.String(35))
- created = db.Column(db.DateTime)
- lastpw = db.Column(db.DateTime)
- lastlogin = db.Column(db.DateTime)
- email = db.Column(db.String(200), nullable=False, server_default=db.FetchedValue())
- company = db.Column(db.String(25), nullable=False, index=True, server_default=db.FetchedValue())
- dev = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
- manager = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
- admin = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
- blind = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
- badpwcount = db.Column(db.Integer, server_default=db.FetchedValue())
- t_zipcitycode = db.Table(
- 'zipcitycode',
- db.Column('zipcode', db.String(5), index=True),
- db.Column('city', db.String(50)),
- db.Column('state', db.String(2)),
- db.Column('county', db.String(50)),
- db.Column('percent', db.Integer),
- db.Column('fips', db.String(5)),
- db.Column('direction', db.String(50)),
- db.Column('federal', db.String(70)),
- db.Index('state', 'state', 'city')
- )
- class Zipcode(db.Model):
- __tablename__ = 'zipcode'
- zipcode = db.Column(db.String(5), primary_key=True, nullable=False, index=True, server_default=db.FetchedValue())
- state = db.Column(db.String(2), nullable=False, index=True, server_default=db.FetchedValue())
- county = db.Column(db.String(50), primary_key=True, nullable=False, server_default=db.FetchedValue())
- federal = db.Column(db.String(75), nullable=False, index=True, server_default=db.FetchedValue())
- percent = db.Column(db.Integer, nullable=False, server_default=db.FetchedValue())
- api = Api(app)
- def model_to_dict(model):
- data = {}
- for col in model.__table__.c.keys():
- # data[col] = getattr(c, col, None) # c[col]
- data[col] = str( getattr(model, col, None) ) # c[col]
- return data
-
- class IBRSimple(Resource):
- def get(self, todo_id):
- # Ok, lookup the id, and return the json
- c = Candidate.query.filter_by(ID=todo_id).first()
- return model_to_dict(c)
- # data = {}
- # for col in c.__table__.c.keys():
- # # data[col] = getattr(c, col, None) # c[col]
- # data[col] = str( getattr(c, col, None) ) # c[col]
- # return data
- # {'id': todo_id, 'stuff': True }
- api.add_resource(IBRSimple, '/<string:todo_id>')
- if __name__ == '__main__':
- app.run(port=8080,debug=True)
|