Skip to content

Commit

Permalink
Clean up city parameter references
Browse files Browse the repository at this point in the history
  • Loading branch information
wvanhed committed Jan 2, 2024
1 parent 7f1efc0 commit a201ff3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 24 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -62,15 +61,15 @@ 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
foutafhandeling te voorzien. Het bestand `errors.py` bevat de lijst van
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:
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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(
# "<paste extend_url here>", # adapt this
# False, # set tot True, to actually extend a loan
Expand Down
13 changes: 2 additions & 11 deletions src/mijnbib/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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}")

Expand All @@ -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}")

Expand Down Expand Up @@ -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"
),
)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a201ff3

Please sign in to comment.