stubbing in python version of shipping app
This commit is contained in:
parent
a914a910d0
commit
aede938583
35
src/02-shipping/shipping.py
Normal file
35
src/02-shipping/shipping.py
Normal file
@ -0,0 +1,35 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
from wsgiref.simple_server import make_server
|
||||
|
||||
|
||||
def main(sysargs=sys.argv[:]):
|
||||
app = ShippingApp()
|
||||
port = 18080
|
||||
server = make_server('0.0.0.0', port, app)
|
||||
print('serving {0.__class__.__name__} on port {1}'.format(app, port))
|
||||
server.serve_forever()
|
||||
return 0
|
||||
|
||||
|
||||
class ShippingApp(object):
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
start_response('200 OK', [('content-type', 'text/plain')])
|
||||
return ['oker doke']
|
||||
|
||||
@classmethod
|
||||
def get_shipping_options(cls, zipcode, pounds):
|
||||
base_cost = (float(zipcode) / 10000.0) + (pounds * 5.0)
|
||||
return {
|
||||
"Next Day": int(base_cost * 4),
|
||||
"Two Day Air": int(base_cost * 2),
|
||||
"Saver Ground": int(base_cost)
|
||||
}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
||||
# vim:filetype=python
|
Loading…
Reference in New Issue
Block a user