xms/refresh.py

55 lines
1.4 KiB
Python

#!/usr/bin/python3
from datetime import datetime
import json
import os
from mswalletrpc import MultisigWallet
SETTINGS = json.loads(open('settings.json').read())
def get_wallets():
paths = []
if os.path.isdir('wallets'):
for name in sorted(os.listdir('wallets')):
if os.path.isdir(os.path.join('wallets', name)):
paths.append(name)
if not paths:
return
wallets = {}
for path in paths:
wallet = {'name': path}
fn = os.path.join('wallets', path, 'wallet')
if not os.path.exists(fn):
continue
wallets[path] = os.lstat(fn).st_atime
return wallets
def refresh_wallet(name):
wallet = MultisigWallet(name, SETTINGS)
print(f'Wallet #{name}: start sync...')
wallet.cli_command(
wallet.get_cli_command(),
f'rescan_bc\n{wallet.password}',
)
os.chdir(wallet.default_path)
print(f'Wallet #{name} is done')
if __name__ == '__main__':
wallets = get_wallets()
for name, dt in wallets.items():
print(f'Wallet #{name}\tLast update: {datetime.fromtimestamp(dt).strftime("%Y-%m-%d %H:%M")}')
num = input('Type number or wallet you want to refresh or A/a for all: ')
if num.lower() == 'a':
for name in wallets.keys():
refresh_wallet(name)
else:
if num in wallets:
refresh_wallet(num)
else:
print(f'Wallet #{num} not found')