diff --git a/starling b/starling index 38d4fd5..ab2ab85 100755 --- a/starling +++ b/starling @@ -11,6 +11,7 @@ import datetime import hashlib import io import json +import os import re import requests import sys @@ -96,8 +97,8 @@ class StarlingKey: algorithm = 'ecdsa-sha512' uid_line_re = re.compile(r'^Key Uid:\s*(' + uid_re.pattern + r')\s*$') - def __init__(self, name): - path = f'keys/{name}.key' + def __init__(self, root, name): + path = f'{root}/keys/{name}.key' with io.open(path, 'rb') as fh: line = fh.readline().decode('utf-8').rstrip() match = self.uid_line_re.fullmatch(line) @@ -132,14 +133,15 @@ class StarlingClient: amount_re = re.compile(r'^(\d+)\.(\d\d)$') - def __init__(self): + def __init__(self, root): + self.root = root self.tokens = self.read_tokens('main', 'payments') - self.api_key = StarlingKey('starling-api-key') + self.api_key = StarlingKey(root, 'starling-api-key') def read_tokens(self, *names): tokens = {} for name in names: - with io.open(f'tokens/{name}.txt') as fh: + with io.open(f'{self.root}/tokens/{name}.txt') as fh: tokens[name] = fh.read().rstrip() return tokens @@ -432,7 +434,8 @@ parser = argparse.ArgumentParser( parser.add_argument('action', help='which action to perform', nargs='*') args = parser.parse_args() -client = StarlingClient() +script = os.path.realpath(sys.argv[0]) +client = StarlingClient(os.path.dirname(script)) action_args = args.action if len(action_args) == 0: