Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import logging
- import re
- import subprocess
- import web
- urls = (
- '/([^/]+)/([^/]+)/([0-9]+)', 'Unit'
- )
- app = web.application(urls, globals())
- class Unit:
- def GET(self, unit_from, unit_to, amount):
- arg1 = '{0} {1}'.format(amount, unit_from)
- arg2 = unit_to
- cmd = '/usr/bin/units'
- args = [cmd, arg1, arg2]
- logging.debug(args)
- output = subprocess.check_output(args)
- logging.debug(output)
- lines = output.split('\n')
- logging.debug(lines)
- line = lines[0]
- logging.debug(line)
- value = line[line.index('*')+2:]
- logging.debug('value is {0}'.format(value))
- logging.debug('{0} {1}'.format(value, unit_to))
- ret = {'Amout to convert': amount, 'Unit to convert': unit_from, 'Final Amount': value, 'Final Unit': unit_to}
- return json.dumps(ret)
- if __name__ == "__main__":
- logging.basicConfig(level=logging.FATAL)
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment