Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit f9cdba3

Browse files
authored
Merge pull request #91 from duffelhq/f-strings
Use f-strings in examples output
2 parents 545e373 + 51bea12 commit f9cdba3

File tree

6 files changed

+40
-81
lines changed

6 files changed

+40
-81
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
max-line-length = 90
33
exclude = .tox
44
max-complexity = 10
5+
per-file-ignores =
6+
# The output from examples are longer than the max line length defined above
7+
examples/*.py:E501

examples/book-and-change.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,21 @@
2020
.execute()
2121
)
2222

23-
print("Created offer request: %s" % (offer_request.id))
23+
print(f"Created offer request: {offer_request.id}")
2424

2525
offers = client.offers.list(offer_request.id)
2626
offers_list = list(enumerate(offers))
2727

28-
print("Got %d offers" % len(offers_list))
28+
print(f"Got {len(offers_list)} offers")
2929

3030
selected_offer = offers_list[0][1]
3131

32-
print("Selected offer %s to book" % (selected_offer.id))
32+
print(f"Selected offer {selected_offer.id} to book")
3333

3434
priced_offer = client.offers.get(selected_offer.id)
3535

3636
print(
37-
"The final price for offer %s is %s (%s)"
38-
% (priced_offer.id, priced_offer.total_amount, priced_offer.total_currency)
37+
f"The final price for offer {priced_offer.id} is {priced_offer.total_amount} ({priced_offer.total_currency})"
3938
)
4039

4140
payments = [
@@ -66,10 +65,7 @@
6665
.execute()
6766
)
6867

69-
print(
70-
"Created order %s with booking reference %s"
71-
% (order.id, order.booking_reference)
72-
)
68+
print(f"Created order {order.id} with booking reference {order.booking_reference}")
7369

7470
order_change_request_slices = {
7571
"add": [
@@ -99,13 +95,12 @@
9995
order_change_offers_list = list(enumerate(order_change_offers))
10096

10197
print(
102-
"Got %d options for changing the order; picking first option"
103-
% (len(order_change_offers_list))
98+
f"Got {len(order_change_offers_list)} options for changing the order; picking first option"
10499
)
105100

106101
order_change = client.order_changes.create(order_change_offers_list[0][1].id)
107102

108-
print("Created order change %s, confirming..." % order_change.id)
103+
print(f"Created order change {order_change.id}, confirming...")
109104

110105
payment = {
111106
"amount": order_change.change_total_amount,
@@ -116,10 +111,5 @@
116111
client.order_changes.confirm(order_change.id, payment)
117112

118113
print(
119-
"Processed change to order %s costing %s (%s)"
120-
% (
121-
order.id,
122-
order_change.change_total_amount,
123-
order_change.change_total_currency,
124-
)
114+
f"Processed change to order {order.id} costing {order_change.change_total_amount} ({order_change.change_total_currency})"
125115
)

examples/book-with-adult-and-infant.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,26 @@
2323
.execute()
2424
)
2525

26-
print("Created offer request: %s" % (offer_request.id))
26+
print(f"Created offer request: {offer_request.id}")
2727

2828
offers = client.offers.list(offer_request.id)
2929
offers_list = list(enumerate(offers))
3030

31-
print("Got %d offers" % len(offers_list))
31+
print(f"Got {len(offers_list)} offers")
3232

3333
selected_offer = offers_list[0][1]
3434

35-
print("Selected offer %s to book" % (selected_offer.id))
35+
print(f"Selected offer {selected_offer.id} to book")
3636

3737
priced_offer = client.offers.get(selected_offer.id)
3838

3939
print(
40-
"The final price for offer %s is %s (%s)"
41-
% (priced_offer.id, priced_offer.total_amount, priced_offer.total_currency)
40+
f"The final price for offer {priced_offer.id} is {priced_offer.total_amount} ({priced_offer.total_currency})"
4241
)
4342

4443
payments = [
4544
{
46-
"currency": selected_offer.total_currency,
45+
"currency": priced_offer.total_currency,
4746
"amount": priced_offer.total_amount,
4847
"type": "balance",
4948
}
@@ -90,22 +89,14 @@
9089
.execute()
9190
)
9291

93-
print(
94-
"Created order %s with booking reference %s"
95-
% (order.id, order.booking_reference)
96-
)
92+
print(f"Created order {order.id} with booking reference {order.booking_reference}")
9793

9894
order_cancellation = client.order_cancellations.create(order.id)
9995

10096
print(
101-
"Requested refund quote for order %s – %s (%s) is available"
102-
% (
103-
order.id,
104-
order_cancellation.refund_amount,
105-
order_cancellation.refund_currency,
106-
)
97+
f"Requested refund quote for order {order.id}{order_cancellation.refund_amount} ({order_cancellation.refund_currency}) is available"
10798
)
10899

109100
client.order_cancellations.confirm(order_cancellation.id)
110101

111-
print("Confirmed refund quote for order %s" % (order.id))
102+
print(f"Confirmed refund quote for order {order.id}")

examples/book-with-seat.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,21 @@
2222
.execute()
2323
)
2424

25-
print("Created offer request: %s" % (offer_request.id))
25+
print(f"Created offer request: {offer_request.id}")
2626

2727
offers = client.offers.list(offer_request.id)
2828
offers_list = list(enumerate(offers))
2929

30-
print("Got %d offers" % len(offers_list))
30+
print(f"Got {len(offers_list)} offers")
3131

3232
selected_offer = offers_list[0][1]
3333

34-
print("Selected offer %s to book" % (selected_offer.id))
34+
print(f"Selected offer {selected_offer.id} to book")
3535

3636
priced_offer = client.offers.get(selected_offer.id)
3737

3838
print(
39-
"The final price for offer %s is %s (%s)"
40-
% (priced_offer.id, priced_offer.total_amount, priced_offer.total_currency)
39+
f"The final price for offer {priced_offer.id} is {priced_offer.total_amount} ({priced_offer.total_currency})"
4140
)
4241

4342
seat_maps = client.seat_maps.get(priced_offer.id)
@@ -58,12 +57,7 @@
5857
available_seat_service = available_seat.available_services[0]
5958

6059
print(
61-
"Adding seat %s costing %s (%s)"
62-
% (
63-
available_seat.designator,
64-
available_seat_service.total_amount,
65-
available_seat_service.total_currency,
66-
)
60+
f"Adding seat {available_seat.designator} costing {available_seat_service.total_amount} ({available_seat_service.total_currency})"
6761
)
6862

6963
total_amount = str(
@@ -106,7 +100,4 @@
106100
.execute()
107101
)
108102

109-
print(
110-
"Created order %s with booking reference %s"
111-
% (order.id, order.booking_reference)
112-
)
103+
print(f"Created order {order.id} with booking reference {order.booking_reference}")

examples/hold-and-pay-later.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
.execute()
2222
)
2323

24-
print("Created offer request: %s" % (offer_request.id))
24+
print(f"Created offer request: {offer_request.id}")
2525

2626
offers = client.offers.list(offer_request.id)
2727
offers_list = list(enumerate(offers))
2828

29-
print("Got %d offers" % len(offers_list))
29+
print(f"Got {len(offers_list)} offers")
3030

3131
selected_offer = offers_list[0][1]
3232

33-
print("Selected offer %s to book" % (selected_offer.id))
33+
print(f"Selected offer {selected_offer.id} to book")
3434

3535
priced_offer = client.offers.get(selected_offer.id)
3636
passengers = [
@@ -55,15 +55,13 @@
5555
)
5656

5757
print(
58-
"Created hold order %s with booking reference %s"
59-
% (order.id, order.booking_reference)
58+
f"Created hold order {order.id} with booking reference {order.booking_reference}"
6059
)
6160

6261
updated_order = client.orders.get(order.id)
6362

6463
print(
65-
"Retrieved order and up-to-date price is %s (%s)"
66-
% (updated_order.total_amount, updated_order.total_currency)
64+
f"Retrieved order and up-to-date price is {updated_order.total_amount} ({updated_order.total_currency})"
6765
)
6866

6967
payment = (
@@ -79,8 +77,8 @@
7977
.execute()
8078
)
8179

82-
print("Paid for order %s with payment %s" % (order.id, payment.id))
80+
print(f"Paid for order {order.id} with payment {payment.id}")
8381

8482
paid_order = client.orders.get(order.id)
8583

86-
print("After payment, order has %d documents" % len(paid_order.documents))
84+
print(f"After payment, order has {len(paid_order.documents)} documents")

examples/search-and-book.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,27 @@
2222
.execute()
2323
)
2424

25-
print("Created offer request: %s" % (offer_request.id))
25+
print(f"Created offer request: {offer_request.id}")
2626

2727
offers = client.offers.list(offer_request.id)
2828
offers_list = list(enumerate(offers))
2929

30-
print("Got %d offers" % len(offers_list))
30+
print(f"Got {len(offers_list)} offers")
3131

3232
selected_offer = offers_list[0][1]
3333

34-
print("Selected offer %s to book" % (selected_offer.id))
34+
print(f"Selected offer {selected_offer.id} to book")
3535

3636
priced_offer = client.offers.get(selected_offer.id, return_available_services=True)
3737

3838
print(
39-
"The final price for offer %s is %s (%s)"
40-
% (priced_offer.id, priced_offer.total_amount, priced_offer.total_currency)
39+
f"The final price for offer {priced_offer.id} is {priced_offer.total_amount} ({priced_offer.total_currency})"
4140
)
4241

4342
available_service = priced_offer.available_services[0]
4443

4544
print(
46-
"Adding an extra bag with service %s, costing %s (%s)"
47-
% (
48-
available_service.id,
49-
available_service.total_amount,
50-
available_service.total_currency,
51-
)
45+
f"Adding an extra bag with service {available_service.id}, costing {available_service.total_amount} ({available_service.total_currency})"
5246
)
5347

5448
total_amount = str(
@@ -89,22 +83,14 @@
8983
.execute()
9084
)
9185

92-
print(
93-
"Created order %s with booking reference %s"
94-
% (order.id, order.booking_reference)
95-
)
86+
print(f"Created order {order.id} with booking reference {order.booking_reference}")
9687

9788
order_cancellation = client.order_cancellations.create(order.id)
9889

9990
print(
100-
"Requested refund quote for order %s – %s (%s) is available"
101-
% (
102-
order.id,
103-
order_cancellation.refund_amount,
104-
order_cancellation.refund_currency,
105-
)
91+
f"Requested refund quote for order {order.id}{order_cancellation.refund_amount} ({order_cancellation.refund_currency}) is available"
10692
)
10793

10894
client.order_cancellations.confirm(order_cancellation.id)
10995

110-
print("Confirmed refund quote for order %s" % (order.id))
96+
print(f"Confirmed refund quote for order {order.id}")

0 commit comments

Comments
 (0)