Created
September 4, 2016 15:13
-
-
Save eskilandreen/2849cdfe18cb9ca6e25b7905152fff88 to your computer and use it in GitHub Desktop.
Quick and dirty python service
This file contains 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 route, run | |
from mako.template import Template | |
import requests | |
template = Template(''' | |
<dl> | |
<dd>Name</dd> | |
<dt>${merchant['name']}</dt> | |
<dd>Number of bills</dd> | |
<dt>${len(merchant['bills'])}</dt> | |
<dd>Total of bills</dd> | |
<dt>${sum(x['amount'] for x in merchant['bills'])}</dt> | |
</div> | |
''') | |
def query_merchant(merchant_id): | |
return requests.get('http://merchants/merchant/' + merchant_id).json() | |
def add_billing(merchant): | |
res = requests.get('http://billing/merchant/' + merchant['id']) | |
merchant['bills'] = res.json() | |
@route('/merchants/<merchant_id>') | |
def get_merchant(merchant_id): | |
merchant = query_merchant(merchant_id) | |
add_billing(merchant) | |
return template.render(merchant=merchant) | |
if __name__ == '__main__': | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment