Return accounts in `bidict`

fsp_feeds
Tyler Goodlet 2021-09-08 14:01:54 -04:00
parent 063788499a
commit 0d2cddec9a
2 changed files with 13 additions and 5 deletions

View File

@ -22,6 +22,7 @@ from os.path import dirname
import shutil
from typing import Optional
from bidict import bidict
import toml
import click
@ -104,10 +105,13 @@ def write(
return toml.dump(config, cf)
def load_accounts() -> dict[str, Optional[str]]:
def load_accounts(
provider: Optional[str] = None
) -> bidict[str, Optional[str]]:
# our default paper engine entry
accounts: dict[str, Optional[str]] = {'paper': None}
accounts = bidict({'paper': None})
conf, path = load()
section = conf.get('accounts')
@ -116,6 +120,10 @@ def load_accounts() -> dict[str, Optional[str]]:
else:
for brokername, account_labels in section.items():
if (
provider is None or
provider and brokername == provider
):
for name, value in account_labels.items():
accounts[f'{brokername}.{name}'] = value