Skip to content

Instantly share code, notes, and snippets.

Created Feb 17, 2013
What would you like to do?
Takes a partial trade id and searches a mongo database for matches
#!/usr/bin/env python
from bottle import ServerAdapter
import bottle
import sys
import pymongo
import re
import logging
# specialising for cherrypy backend using
# in readme
# New class inherits from ServerAdapter
class MySSLCherryPy(ServerAdapter):
def run(self, handler):
from cherrypy import wsgiserver
server = wsgiserver.CherryPyWSGIServer((, self.port), handler)
# If cert valeu has valid path, SSL will be used
# set it to None to disable SSL
cert = './testserver.pem'
server.ssl_certificate = cert
server.ssl_private_key = cert
def home_page():
return bottle.template('hello_get_value.tpl')'/enrich_display')
def enrich_display():
//do not really need safe here as not inserting or updating
connection = pymongo.Connection("mongodb://", safe=True)
db = connection.testbottle
tradeSet = db.trades
tradeId = bottle.request.forms.get("tradeId")
cond = re.compile("^" + tradeId)
trades = tradeSet.find({'Trade_Id' : cond}).limit(10)
//grab one for display
if (trades.count() > 0):
trade = trades[0]
trade = None
#print (trade)
return bottle.template("show_trade.tpl", {'trade' : trade, 'trades' : trades, 'criterium' : tradeId})
def test_page():
return "<html><title>TestPage</title><body>This is a test page</body></html>"
# playing with logging
logging.basicConfig( level=logging.DEBUG,
format='%(asctime)s | %(levelname)s | find_trade | | %(process)s | %(message)s',
# Add our new MySSLCherryPy class to the supported servers
# under the key 'mysslcherrypy'
bottle.server_names['mysslcherrypy'] = MySSLCherryPy
# reloader restarts it if you update this file'', port='8082', server='mysslcherrypy', reloader=True)'Finished')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment