Compare commits
1 Commits
2a4aff75f0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 41afddfaff |
15
starling
15
starling
@@ -11,6 +11,7 @@ import datetime
|
|||||||
import hashlib
|
import hashlib
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
import sys
|
import sys
|
||||||
@@ -96,8 +97,8 @@ class StarlingKey:
|
|||||||
algorithm = 'ecdsa-sha512'
|
algorithm = 'ecdsa-sha512'
|
||||||
uid_line_re = re.compile(r'^Key Uid:\s*(' + uid_re.pattern + r')\s*$')
|
uid_line_re = re.compile(r'^Key Uid:\s*(' + uid_re.pattern + r')\s*$')
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, root, name):
|
||||||
path = f'keys/{name}.key'
|
path = f'{root}/keys/{name}.key'
|
||||||
with io.open(path, 'rb') as fh:
|
with io.open(path, 'rb') as fh:
|
||||||
line = fh.readline().decode('utf-8').rstrip()
|
line = fh.readline().decode('utf-8').rstrip()
|
||||||
match = self.uid_line_re.fullmatch(line)
|
match = self.uid_line_re.fullmatch(line)
|
||||||
@@ -132,14 +133,15 @@ class StarlingClient:
|
|||||||
|
|
||||||
amount_re = re.compile(r'^(\d+)\.(\d\d)$')
|
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.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):
|
def read_tokens(self, *names):
|
||||||
tokens = {}
|
tokens = {}
|
||||||
for name in names:
|
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()
|
tokens[name] = fh.read().rstrip()
|
||||||
return tokens
|
return tokens
|
||||||
|
|
||||||
@@ -432,7 +434,8 @@ parser = argparse.ArgumentParser(
|
|||||||
parser.add_argument('action', help='which action to perform', nargs='*')
|
parser.add_argument('action', help='which action to perform', nargs='*')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
client = StarlingClient()
|
script = os.path.realpath(sys.argv[0])
|
||||||
|
client = StarlingClient(os.path.dirname(script))
|
||||||
|
|
||||||
action_args = args.action
|
action_args = args.action
|
||||||
if len(action_args) == 0:
|
if len(action_args) == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user