beancount-gocardless 0.1.7__py3-none-any.whl → 0.1.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,10 @@
1
- from .client import NordigenClient # noqa: F401
2
- from .importer import NordigenImporter # noqa: F401
1
+ """
2
+ Simple GoCardless Bank Account Data API Client
3
+ Generated from swagger.json to provide a clean, typed interface.
4
+ """
5
+
6
+ from .client import GoCardlessClient
7
+ from .importer import GoCardLessImporter
8
+ from .models import *
9
+
10
+ __all__ = ["GoCardlessClient", "GoCardLessImporter"]
@@ -1,31 +1,50 @@
1
1
  import argparse
2
2
  import sys
3
3
  import os
4
- from .client import NordigenClient
4
+ import logging
5
+ from beancount_gocardless.client import GoCardlessClient
6
+ from beancount_gocardless.models import AccountInfo
5
7
 
6
8
 
7
- def parse_args():
8
- """
9
- Parses command-line arguments.
9
+ logging.basicConfig(level=os.environ.get("LOGLEVEL", logging.INFO))
10
+ logger = logging.getLogger(__name__)
11
+
12
+
13
+ def display_account(index: int, account: AccountInfo) -> None:
14
+ """Helper function to display account information."""
15
+ iban = account.get("iban", "no-iban")
16
+ currency = "no-currency" # not in AccountInfo
17
+ name = account.get("name", "no-name")
18
+ institution_id = account.get("institution_id", "no-institution")
19
+ requisition_ref = account.get("requisition_reference", "no-ref")
20
+ account_id = account.get("id", "no-id")
21
+ logger.info(
22
+ f"{index}: {institution_id} {name}: {iban} {currency} ({requisition_ref}/{account_id})"
23
+ )
24
+
10
25
 
11
- Returns:
12
- argparse.Namespace: An object containing the parsed arguments.
13
- """
14
- parser = argparse.ArgumentParser(description="Nordigen CLI Utility")
26
+ def parse_args():
27
+ parser = argparse.ArgumentParser(description="GoCardless CLI Utility")
15
28
  parser.add_argument(
16
29
  "mode",
17
- choices=["list_banks", "create_link", "list_accounts", "delete_link"],
30
+ choices=[
31
+ "list_banks",
32
+ "create_link",
33
+ "list_accounts",
34
+ "delete_link",
35
+ "balance",
36
+ ],
18
37
  help="Operation mode",
19
38
  )
20
39
  parser.add_argument(
21
40
  "--secret_id",
22
- default=os.getenv("NORDIGEN_SECRET_ID"),
23
- help="API secret ID (defaults to env var NORDIGEN_SECRET_ID)",
41
+ default=os.getenv("GOCARDLESS_SECRET_ID"),
42
+ help="API secret ID (defaults to env var GOCARDLESS_SECRET_ID)",
24
43
  )
25
44
  parser.add_argument(
26
45
  "--secret_key",
27
- default=os.getenv("NORDIGEN_SECRET_KEY"),
28
- help="API secret key (defaults to env var NORDIGEN_SECRET_KEY)",
46
+ default=os.getenv("GOCARDLESS_SECRET_KEY"),
47
+ help="API secret key (defaults to env var GOCARDLESS_SECRET_KEY)",
29
48
  )
30
49
  parser.add_argument(
31
50
  "--country", default="GB", help="Country code for listing banks"
@@ -34,48 +53,55 @@ def parse_args():
34
53
  "--reference", default="beancount", help="Unique reference for bank linking"
35
54
  )
36
55
  parser.add_argument("--bank", help="Bank ID for linking")
56
+ parser.add_argument("--account", help="Account ID for operations")
57
+ parser.add_argument("--cache", action="store_true", help="Enable caching")
58
+ parser.add_argument(
59
+ "--cache_backend", default="sqlite", help="Cache backend (sqlite, memory, etc.)"
60
+ )
61
+ parser.add_argument(
62
+ "--cache_expire",
63
+ type=int,
64
+ default=0,
65
+ help="Cache expiration in seconds (0 = never expire)",
66
+ )
67
+ parser.add_argument(
68
+ "--cache_name", default="gocardless", help="Cache name/database file"
69
+ )
70
+
37
71
  return parser.parse_args()
38
72
 
39
73
 
40
74
  def main():
41
- """
42
- The main entry point for the CLI.
43
-
44
- Executes the specified operation based on the parsed command-line arguments.
45
- """
46
75
  args = parse_args()
47
76
 
48
77
  if not args.secret_id or not args.secret_key:
49
- print(
50
- "Error: Secret ID and Secret Key are required (pass as args or set env vars NORDIGEN_SECRET_ID and NORDIGEN_SECRET_KEY)",
51
- file=sys.stderr,
78
+ logger.error(
79
+ "Error: Secret ID and Secret Key are required (pass as args or set env vars GOCARDLESS_SECRET_ID and GOCARDLESS_SECRET_KEY)",
52
80
  )
53
81
  sys.exit(1)
54
82
 
55
- client = NordigenClient(
56
- args.secret_id,
57
- args.secret_key,
58
- {},
59
- )
83
+ try:
84
+ logger.debug("Initializing GoCardlessClient")
85
+
86
+ # Build cache options
87
+ cache_options = None
88
+ if args.cache:
89
+ cache_options = {
90
+ "cache_name": args.cache_name,
91
+ "backend": args.cache_backend,
92
+ "expire_after": args.cache_expire,
93
+ "old_data_on_error": True,
94
+ "match_headers": False,
95
+ "cache_control": False,
96
+ }
60
97
 
61
- if args.mode == "list_banks":
62
- banks = client.list_banks(args.country)
63
- for b in banks:
64
- print(b["name"] + ": " + b["id"])
65
- elif args.mode == "create_link":
66
- if not args.bank:
67
- print("--bank is required for create_link", file=sys.stderr)
68
- sys.exit(1)
69
- print(client.create_link(args.reference, args.bank))
70
- elif args.mode == "list_accounts":
71
- accounts = client.list_accounts()
72
- for a in accounts:
73
- print(
74
- f"{a['institution_id']} {a['name']}: {a['iban']} {a['currency']} ({a['reference']}/{a['id']})"
75
- )
76
-
77
- elif args.mode == "delete_link":
78
- print(client.delete_link(args.reference))
98
+ # client = GoCardlessClient(
99
+ # args.secret_id, args.secret_key, cache_options=cache_options
100
+ # )
101
+
102
+ except Exception as e:
103
+ logger.error(f"Error: {e}")
104
+ sys.exit(1)
79
105
 
80
106
 
81
107
  if __name__ == "__main__":