diff options
| author | Anton Bobov <abobov@gmail.com> | 2020-02-27 21:50:14 +0500 |
|---|---|---|
| committer | Anton Bobov <abobov@gmail.com> | 2020-02-27 21:50:14 +0500 |
| commit | 36e6977442bab1724135ab60b171d59b38bb7111 (patch) | |
| tree | fa465b79483b900e56e8b63c6ea9ee59d07a3fdb | |
| parent | d34161bbda6781a617705ee429776e53768c7b51 (diff) | |
Update to python3
| -rwxr-xr-x | git-split | 4 | ||||
| -rwxr-xr-x | ledger-price-db-update.py | 12 | ||||
| -rwxr-xr-x | worth-it | 18 |
3 files changed, 19 insertions, 15 deletions
@@ -1,6 +1,10 @@ #!/usr/bin/env bash # https://stackoverflow.com/questions/40698651/how-to-split-every-commit-by-file # Split HEAD commit into multiples with single file in it. +# +# If you want to split a single commit during an interactive rebase, use it like this: +# p Commit to split +# x git-split set -e diff --git a/ledger-price-db-update.py b/ledger-price-db-update.py index 0a78585..853cfe9 100755 --- a/ledger-price-db-update.py +++ b/ledger-price-db-update.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import sys @@ -31,7 +31,7 @@ from codecs import open CONFIG_FILE = '~/.ledger-commodities' config = ConfigParser() -config.readfp(open(os.path.expanduser(CONFIG_FILE), 'r', 'utf-8')) +config.read_file(open(os.path.expanduser(CONFIG_FILE), 'r', 'utf-8')) def get_json(url, **kwargs): @@ -43,7 +43,7 @@ def print_price(symbol, price, base, date=datetime.datetime.now()): date_str = date.strftime('%Y/%m/%d %H:%M:%S') if ' ' in symbol: symbol = '"' + symbol +'"' - print ('P %s %s %f %s' % (date_str, symbol, price, base)).encode('utf-8') + print(('P %s %s %f %s' % (date_str, symbol, price, base))) def exchange_rates(): @@ -51,12 +51,12 @@ def exchange_rates(): symbols = dict([(symbol.upper(), commodity) for symbol, commodity in config.items('exchange-symbols')]) params = { "access_key": config.get('fixer', 'access_key'), - "symbols": ','.join(symbols.keys() + [base,]) + "symbols": ','.join(list(symbols.keys()) + [base,]) } rates = get_json(r'http://data.fixer.io/api/latest', params=params)['rates'] base_value = rates[base] - for symbol, value in rates.items(): + for symbol, value in list(rates.items()): if symbol != base: print_price(symbols[symbol], base_value / value, symbols[base]) @@ -127,7 +127,7 @@ def main(): try: update() except Exception as e: - print >> sys.stderr, 'Oops, update method `%s` failed: %s' % (update, e) + print('Oops, update method `%s` failed: %s' % (update, e), file=sys.stderr) traceback.print_exc() if __name__ == '__main__': @@ -1,16 +1,16 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- def read_data(): data = [] while True: - text = raw_input() + text = input() if text == '': break try: sp = text.split() - (value, cost) = map(float, sp) + (value, cost) = list(map(float, sp)) data.append((cost / value, value, cost, text)) except ValueError: pass @@ -18,16 +18,16 @@ def read_data(): def main(): - print 'Enter data table (last line should be empty): value cost' - print + print('Enter data table (last line should be empty): value cost') + print() data = sorted(read_data()) if len(data): - print '%10s | %10s | %10s' % ("Ratio", "Value", "Cost") + print('%10s | %10s | %10s' % ("Ratio", "Value", "Cost")) for ratio, _, _, orig_value in data: - print '%10.2f | %10s | %10s' % tuple([ratio, ] + orig_value.split()) - print - print 'Best choose is %s' % data[0][-1] + print('%10.2f | %10s | %10s' % tuple([ratio, ] + orig_value.split())) + print() + print('Best choose is %s' % data[0][-1]) if __name__ == '__main__': |
