Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError fix when config_file is None #13

Merged
merged 1 commit into from
May 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions pylnbits/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ def __init__(self, config_file: str = "",

try:
if config_file:
if not os.path.exists(config_file):
raise FileNotFoundError(f"Config file: {config_file} not found!")

with open(config_file, "rb") as f:
cfile = safe_load(f)
print(cfile)
f.close()
# add file error checking
self._in_key = cfile["in_key"]
self._lnbits_url = cfile["lnbits_url"]
self._admin_key = cfile["admin_key"]

# add file error checking
self._in_key = cfile["in_key"]
self._lnbits_url = cfile["lnbits_url"]
self._admin_key = cfile["admin_key"]

except Exception as e:
print(e)
return e
Expand Down Expand Up @@ -63,11 +68,15 @@ def admin_headers(self):


if __name__ == "__main__":
c = Config(config_file="/Users/bitcarrot/laisee/pylnbits/config.yml")

print(c.in_key)
print(c.admin_key)
print(c.lnbits_url)
print(c.headers())
print(c.invoice_headers())
print(c.admin_headers())
c = Config(
in_key="test",
admin_key="test",
lnbits_url="https://legend.lnbits.com"
)

print(f"{c.in_key=}")
print(f"{c.admin_key=}")
print(f"{c.lnbits_url=}")
print(f"{c.headers()=}")
print(f"{c.invoice_headers()=}")
print(f"{c.admin_headers()=}")