-
-
Save amundo/5383571 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import Bottle | |
from sqlalchemy import create_engine | |
from sqlalchemy import MetaData | |
from sqlalchemy import Table | |
app = Bottle() | |
DB_CONN = 'sqlite:///malaysian_mp_profile.sqlite' | |
engine = create_engine(DB_CONN) | |
meta = MetaData() | |
meta.bind = engine | |
meta.create_all() | |
swdata = Table('swdata',meta,autoload=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from base import app | |
from base import engine | |
from base import swdata | |
from bottle import request | |
from bottle import response | |
from bottle import route | |
@app.route('/mp/api/list/') | |
def mp_list(): | |
result = engine.execute('select * from swdata') | |
all_data = [] | |
for item in result.fetchall(): | |
data = {} | |
for key in result.keys(): | |
data[key] = item[key] | |
all_data.append(data) | |
return {'data':all_data} | |
@app.route('/mp/api/view/',method='GET') | |
def mp_view(): | |
id = request.GET.get('id') | |
print id | |
query = swdata.select(swdata.c.key == int(id)) | |
result = engine.execute(query) | |
data = {} | |
output = result.fetchone() | |
for i in output.keys(): | |
data[i] = output[i] | |
return data | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bottle import run | |
from bottle import debug | |
from base import app | |
from mp_profile import mp_list | |
from mp_profile import mp_view | |
debug(True) | |
run(app,host='localhost',port='8080') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment