diff --git a/src/classes.py b/src/classes.py index 52a1a80..71258b4 100644 --- a/src/classes.py +++ b/src/classes.py @@ -1,10 +1,12 @@ from utils import raiseDiscord +import config +import json class Travel(): def __init__(self, data): self.orderId = data["orderId"] self.serviceItemId = data["serviceItemId"] - self.dvNumber = data["dvNumber"] + self.dvNumber = data["dvNumber"] # or marketingCarrierRef, the ref of the visible ticket's ref self.origin = data["origin"] self.destination = data["destination"] self.departureDateTime = data["departureDateTime"] @@ -16,9 +18,11 @@ class Travel(): self.seatNumber = data["seatNumber"] self.reservationDate = data["reservationDate"] - self.travelConfirmed = data["travelConfirmed"] # CONFIRMED, TOO_EARLY_TO_CONFIRM + self.travelConfirmed = data["travelConfirmed"] # CONFIRMED, TOO_EARLY_TO_CONFIRM, TO_BE_CONFIRMED self.travelStatus = data["travelStatus"] + self.tcn = None + def confirm(self, session, headers): """ https://www.maxjeune-tgvinoui.sncf/api/public/reservation/travel-confirm @@ -42,4 +46,30 @@ class Travel(): return r + def get(self, s, headers): + r = s.post( + "https://www.maxjeune-tgvinoui.sncf/api/public/reservation/get-travel", + headers=headers, + json = { + "customerName": config.customer_name, + "departureDateTime": self.departureDateTime, + "marketingCarrierRef": self.dvNumber, + "trainNumber": self.trainNumber + }) + data = json.loads(r.content.decode("utf-8")) + self.tcn = data["tcn"] + return data + + def tprint(self, s, headers): + if self.tcn is None: + self.get(s, headers) + + return s.post( + "https://www.maxjeune-tgvinoui.sncf/api/public/reservation/print-travel", + headers=headers, + json = { + "orderId": self.orderId, + "serviceItemId": self.serviceItemId, + "tcn": [self.tcn] + })