From a201ff3f5585c6feadefa4b35f0cd9b11070cfcf Mon Sep 17 00:00:00 2001 From: Ward Van Heddeghem Date: Tue, 2 Jan 2024 20:36:13 +0100 Subject: [PATCH] Clean up city parameter references --- README.md | 11 +++++------ changelog.md | 1 + examples/example.py | 14 +++++++------- src/mijnbib/__main__.py | 13 ++----------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 67c0c1b..71b2961 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,11 @@ Bijvoorbeeld, het opvragen van je ontleende items kan als volgt (na installatie) from mijnbib import MijnBibliotheek - city = "gent" # jouw gemeente of stad username = "johndoe" password = "12345678" account_id = "12345" # zie het getal in de URL, of via mb.get_accounts() - mb = MijnBibliotheek(username, password, city) + mb = MijnBibliotheek(username, password) loans = mb.get_loans(account_id) print(loans) @@ -62,7 +61,7 @@ Tenslotte, via de commandline kan je de module ook als volgt aanroepen: via een webformulier. Het is ook mogelijk om de snellere `oauth` manier te gebruiken; dit is nog experimenteel. - mb = MijnBibliotheek(username, password, city, login_by="oauth") + mb = MijnBibliotheek(username, password, login_by="oauth") accounts = mb.get_accounts() - **Foutafhandeling**. Afhankelijk van de toepassing, kan het aangeraden zijn om @@ -70,7 +69,7 @@ Tenslotte, via de commandline kan je de module ook als volgt aanroepen: Mijnbib-specifieke exceptions. De docstrings van de publieke methods bevatten de errors die kunnen optreden. Bijvoorbeeld: - mb = MijnBibliotheek(username, password, city) + mb = MijnBibliotheek(username, password) try: accounts = mb.get_accounts() except AuthenticationError as e: @@ -113,8 +112,8 @@ To work around the challenge of testing a web scraper, the following *snapshot testing* approach can be used to get some confidence when applying refactoring: 1. Create a file `mijnbib.ini` in the project root folder, and make it contain - a section `[DEFAULT]` holding the following parameters: `city`, `username`, - `password` and `account_id` + a section `[DEFAULT]` holding the following parameters: `username`, + `password`, `city` and `account_id` 2. Run `python tests/save_testref.py` to capture and store the current output (a couple of files will be created) 3. Perform refactoring as needed diff --git a/changelog.md b/changelog.md index b5af76f..c9fae7d 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,7 @@ new: new feature / impr: improvement / fix: bug fix ## WIP - new: experimental login via OAuth (optional) +- new: city parameter to create MijnBibliotheek object is now optional - impr: set some log messages at INFO level ## v0.3.0 - 2023-12-27 diff --git a/examples/example.py b/examples/example.py index 30f5ec6..9d66c78 100644 --- a/examples/example.py +++ b/examples/example.py @@ -8,29 +8,29 @@ logging.getLogger().setLevel(logging.DEBUG) pp = pprint.PrettyPrinter() -# Change these values !!! -city = "gent" +# Change the following values to match your situation +# city = "gent" # this used to be required, but is optional since January 2024 username = "johndoe" password = "password" account_id = "123456" print("\nFetching accounts...") -mb = MijnBibliotheek(username, password, city) +mb = MijnBibliotheek(username, password) accounts = mb.get_accounts() pp.pprint([asdict(acc) for acc in accounts]) print("\nFetching loans...") -mb = MijnBibliotheek(username, password, city) +mb = MijnBibliotheek(username, password) loans = mb.get_loans(account_id) pp.pprint([asdict(loan) for loan in loans]) print("\nFetching reservations...") -mb = MijnBibliotheek(username, password, city) +mb = MijnBibliotheek(username, password) reservations = mb.get_reservations(account_id) pp.pprint([asdict(res) for res in reservations]) print("\nFetching all info...") -mb = MijnBibliotheek(username, password, city) +mb = MijnBibliotheek(username, password) info = mb.get_all_info(all_as_dicts=True) pp.pprint(info) @@ -41,7 +41,7 @@ pp.pprint(extendable_loans) # print("Extending loan...") -# mb = MijnBibliotheek(username, password, city) +# mb = MijnBibliotheek(username, password) # success, details = mb.extend_loans( # "", # adapt this # False, # set tot True, to actually extend a loan diff --git a/src/mijnbib/__main__.py b/src/mijnbib/__main__.py index 12807df..4c1cb31 100644 --- a/src/mijnbib/__main__.py +++ b/src/mijnbib/__main__.py @@ -11,7 +11,6 @@ def _do_login(args: argparse.Namespace): print("Trying to log in ...") - print(f"City: : {args.city}") print(f"Username : {args.username}") @@ -25,8 +24,6 @@ def _do_login(args: argparse.Namespace): def _do_all(args: argparse.Namespace): print("Retrieving all information ...") - - print(f"City: : {args.city}") print(f"Username : {args.username}") mb = MijnBibliotheek(args.username, args.password, args.city) @@ -36,8 +33,6 @@ def _do_all(args: argparse.Namespace): def _do_accounts(args: argparse.Namespace): print("Retrieving accounts ...") - - print(f"City: : {args.city}") print(f"Username : {args.username}") mb = MijnBibliotheek(args.username, args.password, args.city) @@ -47,8 +42,6 @@ def _do_accounts(args: argparse.Namespace): def _do_loans(args: argparse.Namespace): print("Retrieving loans ...") - - print(f"City: : {args.city}") print(f"Username : {args.username}") print(f"Account : {args.accountid}") @@ -59,8 +52,6 @@ def _do_loans(args: argparse.Namespace): def _do_reservations(args: argparse.Namespace): print("Retrieving reservations ...") - - print(f"City: : {args.city}") print(f"Username : {args.username}") print(f"Account : {args.accountid}") @@ -90,7 +81,7 @@ def main(): " [DEFAULT]\n" " username = john\n" " password = 123456\n" - " city = gent\n" + " city = gent (can be blank)\n" " accountid = 456" ), ) @@ -128,7 +119,7 @@ def main(): logging.basicConfig(format="%(levelname)s %(message)s") logging.getLogger().setLevel(logging.DEBUG) - required = ["username", "password", "city"] + required = ["username", "password"] for r in required: if getattr(args, r) is None: print(