Revisions
-
sweemeng revised this gist
Nov 5, 2011 . 2 changed files with 8 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,11 @@ from sqlalchemy import MetaData from sqlalchemy import Table # Main Web App app = Bottle() # Configuration for sqlalchemy # source https://scraperwiki.com/scrapers/malaysian_mp_profile/ DB_CONN = 'sqlite:///malaysian_mp_profile.sqlite' engine = create_engine(DB_CONN) 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 charactersOriginal file line number Diff line number Diff line change @@ -5,10 +5,12 @@ from bottle import response from bottle import route # list MP @app.route('/mp/api/list/') def mp_list(): result = engine.execute('select * from swdata') all_data = [] # convert from sqlalchemy to dict for item in result.fetchall(): data = {} for key in result.keys(): @@ -18,11 +20,12 @@ def mp_list(): return {'data':all_data} # View Indivisual MP @app.route('/mp/api/view/',method='GET') def mp_view(): # get from ?id=n id = request.GET.get('id') query = swdata.select(swdata.c.key == int(id)) result = engine.execute(query) data = {} -
sweemeng revised this gist
Nov 5, 2011 . No changes.There are no files selected for viewing
-
sweemeng created this gist
Nov 5, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ 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')