Exemplo n.º 1
0
def main():

	ipop.cls()

	back = "python3 main_menu.py"
	uok = False

	while True:
		username = ipop.getUserData([str], "||\tEnter username:\n||\t", "Wrong data!")
		if username == None:
			os.system(back)
			break
		else:
			if mdb.checkUsernamePresence(username):
				uok = True
				break
			else: print ("Username not present.")

	while uok:
		password = ipop.getUserData([str], "||\tEnter password:\n||\t", "Wrong data!")
		if password == None:
			os.system(back)
			break
		else:
			r = mdb.doesPasswordMatch(username, password)
			if r == 1:
				if mdb.verifyAdmin(username, password): os.system("python3 admin_page.py '" + username + "'")
				else: os.system("python3 logged_in_main_menu.py '" + username + "'")
				break
			elif r == -1: print ("Wrong password.")
			else:
				print("Error!")
				break
Exemplo n.º 2
0
def main():

    ipop.cls()
    username = sys.argv[1]
    name = mdb.getNameFromUsername(username)

    fdate = ''
    tdate = ''

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tHello administrator,\t\t\t\t\t\t\t|\n" + "|\t" + name + "\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tPlease select the appropriate option:\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)
    print("||\t1. Print entire table")
    print("||\t2. Print revenue between two dates")
    print("||")

    ip = ipop.getUserData([int], "||\tEnter option: ", "Wrong data entered!",
                          True, ["x in [1,2]"], True)
    print()

    if ip != None:
        ipop.cls()
        if ip == 1:
            h, c, t = mdb.getRevenue()
            ipop.print_table((h, c))
            print('\nTotal revenue: ' + str(t))
            p = input("\nPress any key to go to main menu....")
            exit1(username)
        elif ip == 2:
            while True:

                print("||\tEnter a 'from' date (DD/MM/YYYY): ")
                fdate = reqdate()
                if fdate == '':
                    exit1(username)
                    break

                print("||\tEnter a 'to' date (DD/MM/YYYY): ")
                tdate = reqdate()
                if tdate == '':
                    exit1(username)
                    break

                if calc.compareDates(fdate, tdate):
                    h, c, t = mdb.getRevenue(fdate, tdate)
                    ipop.print_table((h, c))
                    print('\nTotal revenue: ' + str(t))
                    p = input("\nPress any key to go to main menu....")
                    exit1(username)
                    break
                else:
                    print(
                        "The 'from' date is later than 'to' date.\nEnter 1 to re-enter the dates !q to quit"
                    )
                    p = ipop.getUserData([int, str], "", "")
                    if p == 1: continue
                    else: break
Exemplo n.º 3
0
def main():

    ipop.cls()

    username = sys.argv[1]

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tWelcome to seat cancellation.\t\t\t\t|\n" + "|\tYou will need to provide the ticket number\t\t|\n" + "|\tof every reservation you wish cancel\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)

    while True:
        ticket_no = ipop.getUserData([str], "||\tEnter ticket number\n||\t",
                                     "Wrong data")
        details = mdb.ticketDetails(ticket_no, 1)
        if details == None:
            print("Ticket number does not exist.")

        elif username != details[2]:
            print("This ticket belongs to a different customer.")

        elif calc.isValidTransactionDate(details[5]):

            username = details[2]
            route_id = details[0]
            bus_id = details[1]
            starting = details[3]
            ending = details[4]
            reservation_date = details[5]
            amount = details[7]

            tickString = "_________________________________________________________________\n" + "||\n" + "||\tReservation in bus ID: " + bus_id + "\n" + "||\tOn route ID: " + route_id + "\n" + "||\tJourney starting from: " + starting + "\n" + "||\tJourney ending at: " + ending + "\n" + "||\tOn date: " + reservation_date + '\n' + "||\tNumber of reservations = 1" + '\n||\n' + "||\tTicket numbers:\n" + '||\t' + ticket_no + '\n' + "||\tTotal amounting to: " + str(
                amount
            ) + '\n' + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

            print(tickString + '\n')

            p = input(
                "To cancel this ticket, press any key or !q to go back....")
            if p != '!q':
                if (mdb.add_cancellation(ticket_no) != 1):
                    print("Ticket could not be cancelled.")
                else:
                    print("Ticket cancelled.")

        else:
            print("This ticket cannot be cancelled.")

        ip = ipop.getUserData(
            [int, str],
            "Enter 1 to enter another ticket number, !q to go to main menu.",
            "Wrong data")
        if ip == 1:
            continue
        else:
            exit1(username)
            break
Exemplo n.º 4
0
def main():

	ipop.cls()
	username = sys.argv[1]
	name = mdb.getNameFromUsername(username)

	screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tHello administrator,\t\t\t\t\t|\n" + "|\t" + name + "\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tSee report on reservation/cancellation\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

	print(screen)

	fdate = ''
	tdate = ''
	cat = 0
	t = ''
	

	while True:
		print("\tCatagories:\n\t1. Sort according to bus IDs\n\t2. According to route IDs\n\t3. According to actual routes\n")
		cat = ipop.getUserData([int], "||\tEnter category: ", "Wrong data entered!", True, ["x in [1,2,3]"], True)
		if cat == None:
			exit1(username)
			break

		print("||\tEnter a 'from' date (DD/MM/YYYY): ")
		fdate = reqdate()
		if fdate == '':
			exit1(username)
			break

		print("||\tEnter a 'to' date (DD/MM/YYYY): ")
		tdate = reqdate()
		if tdate == '':
			exit1(username)
			break
		
		print("\tType:\n\tr. See reservations\n\tc. See cancellations\n")
		t = ipop.getUserData([str], "||\tEnter type: ", "Wrong data entered!", True, ["x in ['r', 'c']"], True)
		if t == None:
			exit1(username)
			break

		print()
		h, c, t = mdb.order_rc_by_catagories(cat, fdate, tdate, t)
		ipop.print_table((h,c))
		print("\nTotal count: " + str(t) + '\n')

		c = ipop.getUserData([int, str], "||\tEnter 1 for re-search, !q to cancel: ", "Wrong data entered!")
		if c != 1:
			exit1(username)
			break
Exemplo n.º 5
0
def main():

    ipop.cls()
    username = sys.argv[1]
    name = mdb.getNameFromUsername(username)

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tHello,\t\t\t\t\t\t\t|\n" + "|\t" + name + "\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tPlease select the appropriate option:\t\t\t|\n" + "|\t1) Bus time table\t\t\t\t\t|\n" + "|\t2) Buses between stops\t\t\t\t\t|\n" + "|\t3) Seat availability\t\t\t\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tStart your journey...\t\t\t\t\t|\n" + "|\t4) Book a seat\t\t\t\t\t\t|\n" + "|\t5) Cancel a seat\t\t\t\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tYour activities\t\t\t\t\t\t|\n" + "|\t6) Your reservations\t\t\t\t\t|\n" + "|\t7) Your cancellations\t\t\t\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tNot " + name + "?\n" + "|\tL) Logout\t\t\t\t\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)

    p = "Enter option (1-7,L): "
    ip = ipop.getUserData([int, str], p, "Wrong data entered!", True,
                          ["x in list(range(1,8))", "x == 'L'"], True)

    if ip == 'L':
        os.system("python3 main_menu.py")
    elif ip == 1:
        os.system("python3 time_table_screen.py '" + username + "'")
    elif ip == 2:
        os.system("python3 buses_between_stops.py '" + username + "'")
    elif ip == 3:
        os.system("python3 seat_availability.py '" + username + "'")
    elif ip == 4:
        os.system("python3 add_reservation.py '" + username + "'")
    elif ip == 5:
        os.system("python3 add_cancellation.py '" + username + "'")
    elif ip == 6:
        os.system("python3 your_reservations.py '" + username + "'")
    elif ip == 7:
        os.system("python3 your_cancellations.py '" + username + "'")
def disp_tt(un, ttlist):

    bus_id = ipop.getUserData([str, int], "||\tEnter bus ID or !q to cancel: ",
                              "Wrong data")

    if bus_id == 'R':
        return -1
    elif bus_id == None:
        return 0
    for (i, b) in ttlist:
        if bus_id == i:
            bus_id = b
            break

    tt = mdb.bus_timetable(bus_id, un)

    if tt == []:
        print("Bus with this ID does not exist.")
        return 1
    else:
        h = ['Bus stop', 'Time']
        c = tt
        tup = (h, c)
        print("\nTime table for: " + bus_id)
        ipop.print_table(tup)
        return 1
Exemplo n.º 7
0
def main():

	ipop.cls()
	mdb.initialise()

	try:
		print(sys.argv[1])
	except: pass

	screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tWelcome\t\t\t\t\t\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tPlease select the appropriate option:\t\t\t|\n" + "|\t1) Bus time table\t\t\t\t\t|\n" + "|\t2) Buses between stops\t\t\t\t\t|\n" + "|\t3) Seat availability\t\t\t\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tLogin and get access to\t\t\t\t\t|\n" + "|\tSeat booking\t\t\t\t\t\t|\n" + "|\tand much more...\t\t\t\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tL) LOGIN\t\t\t\t\t\t|\n" + "|\tNot registered yet? Getting an account is easy\t\t|\n" + "|\tS) SIGN UP >>>>\t\t\t\t\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

	print(screen)

	p = "Enter option (1,2,3,L,S): "
	ip = ipop.getUserData([int, str], p, "Wrong data entered!", True, ["x in [1, 2, 3]", "x in ['L', 'S']"], True)
	if ip == 'L':
		os.system("python3 login_screen.py")
	elif ip == 'S':
		os.system("python3 sign-up_screen.py")
	elif ip == 1:
		os.system("python3 time_table_screen.py")
	elif ip == 2:
		os.system("python3 buses_between_stops.py")
	elif ip == 3:
		os.system("python3 seat_availability.py")
Exemplo n.º 8
0
def main():

	ipop.cls()

	username = ''

	try:
		username = sys.argv[1]
		if mdb.checkUsernamePresence(username) == False: username = ''
	except: pass

	screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tEnter source, destination, date and bus ID of journey\t|\n" + "|\tto get available seats before planning reservation\t|\n" + "|\tExample: Howrah to Haldia on 20/08/2017 in AC8\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

	print (screen)
	print("\nEnter !q to cancel anytime.\n")

	while True:
		r = disp_seats()
		if r == 0:
			exit1(username)
			break
		else:
			ch = ipop.getUserData([int, str], "||\tEnter 1 to see more seat availabilities or !q for main menu.\n\t", "Wrong data.")
			if ch == 1: continue
			else:
				exit1(username)
				break
Exemplo n.º 9
0
def main():

    ipop.cls()
    username = sys.argv[1]
    name = mdb.getNameFromUsername(username)

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tHello administrator,\t\t\t\t\t\t\t|\n" + "|\t" + name + "\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tPlease select the appropriate table:\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)
    print("||\t1. Reservation table")
    print("||\t2. Cancellation table")
    print("||\t3. Route table")
    print("||\t4. Fare chart")
    print("||\t5. Bus table")
    print("||")

    ip = ipop.getUserData([int], "||\tEnter table number: ",
                          "Wrong data entered!", True,
                          ["x in list(range(1,6))"], True)
    print()

    if ip != None:
        ipop.cls()
        mdb.adminDisplayTable(ip)
        p = input("\nPress any key to go to main menu....")

    exit1(username)
Exemplo n.º 10
0
def disp_seats():

	source = ipop.getUserData([str], "||\tEnter source of journey:\n||\t", "Wrong data")
	if source == None:
		return 0

	destination = ipop.getUserData([str], "||\tEnter destination of journey:\n||\t", "Wrong data")
	if destination == None:
		return 0

	
	while True:
		date = ipop.getUserData([str], "||\tEnter date of journey: (as DD/MM/YYYY format):\n||\t", "Wrong data")
		if date == None:
			return 0
		else:
			if calc.isValidTransactionDate(date):
				break
			else: print("Invalid date or wrong date format given.")

	buses = mdb.buses_between_stops(source, destination)
	if buses != []:
		bus_details = []
		for b in buses:
			n_seats = len(mdb.availableSeats(b, source, destination, date))
			bus_details.append((b, n_seats))
		bh = ['Bus ID', 'Seats available']
		print ("\nFollowing buses are available:")
		ipop.print_table((bh, bus_details))
		print()

	bus_id = ipop.getUserData([str], "||\tEnter bus ID:\n||\t", "Wrong data")
	if bus_id == None:
		return 0

	buses = mdb.buses_between_stops(source, destination)
	if bus_id not in buses:
		print ("This journey does not exist!!")
		return 1
	
	seats = mdb.availableSeats(bus_id, source, destination, date)
	if seats == []: print ("No more seats are available in this bus for the given date!")
	else:
		print("||\tAvailable seats are:")
		print(seats)
		return 1
Exemplo n.º 11
0
def disp_bbs(un, bbslist):

    buses = []
    source = ''
    destination = ''
    chflag = 0

    source = ipop.getUserData([
        str, int
    ], "||\tEnter source or previous search option (if available)\n||\tor !q to cancel: ",
                              "Wrong data")

    if source == None:
        return 0
    for (i, d) in bbslist:
        if source == i:
            source = d.split('_')[0]
            destination = d.split('_')[1]
            chflag = 1
            break

    if chflag == 0:
        destination = ipop.getUserData(
            [str, int], "||\tEnter destination of journey or !q to cancel: ",
            "Wrong data")
        if destination == None:
            return 0

    buses = mdb.buses_between_stops(source, destination, un)
    if buses == []:
        print("This route does not exist.")
        return 1
    else:
        l = []
        print('\nFollowing buses are available:')
        print('From ' + source + ' to ' + destination)
        for b in buses:
            l.append(
                (b, mdb.getBusType(b), mdb.getTime(b, source, destination),
                 mdb.getFare(b, source, destination)))
        h = ['Bus ID', 'Bus type', 'Journey time', 'Journey fare']
        ipop.print_table((h, l))
        return 1
Exemplo n.º 12
0
def reqdate():
	d = ''
	while True:
		d = ipop.getUserData([str], '||\t', "Wrong data entered!")
		if d == None:
			return ''
		else:
			if calc.isPreviousDate(d) == False:
				print("Wrong date format or future date entered. Re-enter date or !q to cancel.")
				continue
			else: return d
Exemplo n.º 13
0
def main():

    ipop.cls()

    uok = False

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tSign up to get exclusive benefits!\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)

    name = ipop.getUserData([str], "||\tEnter name: ", "Wrong data!", True,
                            ['x != ""'])

    while True:
        username = ipop.getUserData([str], "||\tEnter username: "******"Wrong data!", True, ['x != ""'])
        if mdb.checkUsernamePresence(username) == False:
            break
        else:
            print("Username already present, choose another username.")

    password = ipop.getUserData([str, int, float], "||\tEnter password: "******"Wrong data!", True, ['x != ""'])

    confirm = "Enter any character to confirm OR '!q' to cancel registration....\n"
    print(confirm)
    c = ipop.getUserData([str], '', 'Enter any character.')

    if c != None:
        try:
            mdb.add_user(name, username, password, '', '')
            alert = "'\nRegistration successful! Please login again..\n'"
            os.system("python3 main_menu.py " + alert)
        except:
            print('Registration unsuccessful..')
            exit(0)
    else:
        alert = "\nRegistration cancelled..\n"
        os.system("python3 main_menu.py")
Exemplo n.º 14
0
def main():

    ipop.cls()

    username = ''

    try:
        username = sys.argv[1]
        if mdb.checkUsernamePresence(username) == False: username = ''
    except:
        pass

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tEnter bus ID to see time-table\t\t\t\t|\n" + "|\tExample: S1, V10, AC5, SL2 etc...\t\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tDon't know bus id? Enter R to see buses between stops.\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)

    ttlist = []

    if username != '':
        try:
            storedtt = mdb.get_user_activity(username, 'time_tables')
            if storedtt != '':
                storedtt = storedtt.split('\n')
                ttlist = list(enumerate(storedtt, start=1))
                print("||\tYour previous searches:\n")
                h = ['Choice', 'Bus ID']
                tup = (h, ttlist)
                ipop.print_table(tup)
                print("||\tYou can enter these choices in place of bus ID.\n")
        except:
            pass

    while True:
        r = disp_tt(username, ttlist)
        if r == 0:
            exit1(username)
            break
        elif r == -1:
            buses_bet_stops(username)
            break
        else:
            ch = ipop.getUserData(
                [int, str],
                "||\tEnter 1 for another search or !q for main menu.\n\t",
                "Wrong data.")
            if ch == 1: continue
            else:
                exit1(username)
                break
Exemplo n.º 15
0
def main():

    ipop.cls()

    username = ''

    try:
        username = sys.argv[1]
        if mdb.checkUsernamePresence(username) == False: username = ''
    except:
        pass

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tEnter source and destination to get avilable buses\t|\n" + "|\tExample: Howrah to Asansol etc...\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)

    bbslist = []

    if username != '':
        try:
            storedbbs = mdb.get_user_activity(username, 'buses_between_stops')
            if storedbbs != '':
                storedbbs = storedbbs.split('\n')
                bbslist = list(enumerate(storedbbs, start=1))
                print("||\tYour previous searches:\n")
                h = ['Choice', 'Buses between stops']
                tup = (h, bbslist)
                ipop.print_table(tup)
                print("||\tYou can enter these choices in starting field.\n")
        except:
            pass

    while True:
        r = disp_bbs(username, bbslist)
        if r == 0:
            exit1(username)
            break
        else:
            ch = ipop.getUserData(
                [int, str],
                "||\tEnter 1 for another search or !q for main menu.\n\t",
                "Wrong data.")
            if ch == 1: continue
            else:
                exit1(username)
                break
Exemplo n.º 16
0
def main():

    ipop.cls()
    username = sys.argv[1]
    name = mdb.getNameFromUsername(username)

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tHello administrator,\t\t\t\t\t|\n" + "|\t" + name + "\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tPlease select the appropriate option:\t\t\t|\n" + "|\t1) Print tables\t\t\t\t\t\t|\n" + "|\t2) Print revenue\t\t\t\t\t|\n" + "|\t3) Sort reservation/cancellation catagory-wise\t\t|\n" + "|\t4) Sort reservation/cancellation month-wise\t\t|\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tL) Logout\t\t\t\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)

    p = "Enter option (1-4,L): "
    ip = ipop.getUserData([int, str], p, "Wrong data entered!", True,
                          ["x in list(range(1,5))", "x == 'L'"], True)

    if ip == 1:
        os.system("python3 display_tables.py '" + username + "'")
    if ip == 2:
        os.system("python3 display_revenue.py '" + username + "'")
    if ip == 3:
        os.system("python3 sort_rc_cat.py '" + username + "'")
    if ip == 4:
        os.system("python3 sort_rc_month.py '" + username + "'")
    elif ip == 'L':
        os.system("python3 main_menu.py")
Exemplo n.º 17
0
def main():

    ipop.cls()
    username = sys.argv[1]
    name = mdb.getNameFromUsername(username)

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tHello administrator,\t\t\t\t\t|\n" + "|\t" + name + "\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tSee report on reservation/cancellation\t\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)

    bid = ''
    rid = ''
    source = ''
    destination = ''
    t = ''

    print(
        "\tEnter ATLEAST bus ID, or route ID or source or destination or their combination.\n"
    )

    while True:
        bid = input("||\tEnter bus ID (leave blank to include all buses): ")
        if bid == '!q':
            exit1(username)
            break
        elif bid == '':
            rid = input(
                "||\tEnter route ID (leave blank to include all routes): ")
            if rid == '!q':
                exit1(username)
                break

        source = input(
            "||\tEnter source (leave blank to include all sources): ")
        if source == '!q':
            exit1(username)
            break

        destination = input(
            "||\tEnter destination (leave blank to include all destinations): "
        )
        if destination == '!q':
            exit1(username)
            break

        t = input("||\tEnter 'r' for reservation or 'c' for cancellation: ")
        if t == '!q':
            exit1(username)
            break

        print()
        h, c = mdb.order_rc_by_month(t, rid, bid, source, destination)
        if c == []:
            print("\nData unavailable.")
        else:
            ipop.print_table((h, c))

        print()
        c = ipop.getUserData([int, str],
                             "||\tEnter 1 for re-search, !q to cancel: ",
                             "Wrong data entered!")
        if c != 1:
            exit1(username)
            break
Exemplo n.º 18
0
def main():

    ipop.cls()

    username = sys.argv[1]

    screen = "_________________________________________________________________\n" + "|\t\t\t\t\t\t\t\t|\n" + "|\tWelcome to seat reservation.\t\t\t\t|\n" + "|\tYou will be guided through the reservation process.\t|\n" + "|\tPlease enter the relevant information as asked.\t\t|\n" + "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"

    print(screen)

    print(
        "\nOn entering the start and end of your journey\nwe will automatically list the available buses for you to choose.\nYou can quit the process anytime by entering !q\n"
    )

    routeFlag = False
    dateFlag = False
    seatFlag = False
    seatReserveFlag = False

    source = ''
    destination = ''
    bus_id = ''
    date = ''
    n = 0
    seats = []
    bookedSeats = []
    fare = 0
    amount = 0

    ts = '00:00'
    te = '00:00'

    tickets = []

    while True:
        date = ipop.getUserData(
            [str], "||\tEnter date of journey: (as DD/MM/YYYY format):\n||\t",
            "Wrong data")
        if date == None:
            return 0
        else:
            if calc.isValidTransactionDate(date):
                dateFlag = True
                break
            else:
                print("Invalid date or wrong date format given.")

    while dateFlag:

        source = ipop.getUserData([str], "||\tEnter source:\n||\t",
                                  "Wrong data")
        if source == None:
            exit1(username)
            break
        destination = ipop.getUserData([str], "||\tEnter destination:\n||\t",
                                       "Wrong data")
        if destination == None:
            exit1(username)
            break
        buses = mdb.buses_between_stops(source, destination)
        if buses == []:
            print(
                "Sorry, this route does not exist. Press 1 to re-enter start and destination, !q to cancel and go to main menu."
            )
            p = ipop.getUserData([str, int], "", "Wrong data")
            if p == 1: continue
            else:
                exit1(username)
                break
        else:
            bus_details = []
            for b in buses:
                bus_type = mdb.getBusType(b)
                bus_fare = mdb.getFare(b, source, destination)
                n_seats = len(mdb.availableSeats(b, source, destination, date))
                bus_details.append((b, bus_type, bus_fare, n_seats))
            bh = ['Bus ID', 'Type', 'Fare', 'Seats available']
            print("\nFollowing buses are available:")
            ipop.print_table((bh, bus_details))
            print()
            bus_id = ipop.getUserData([str], "||\tEnter bus id:\n||\t",
                                      "Choose among the available buses.",
                                      True, ['x in ' + str(buses)], True)
            if bus_id == None:
                exit1(username)
            else:
                routeFlag = True
            break

    if routeFlag:
        print("Almost there....")
        while True:
            n = ipop.getUserData(
                [int], "||\tEnter number of seats to be reserved:\n||\t",
                "Wrong data")
            if n == None:
                exit1(username)
            else:
                seats = mdb.availableSeats(bus_id, source, destination, date)
                if n > len(seats):
                    print(
                        "The requested number of seats is currently not available in "
                        + bus_id + " on " + date)
                    p = ipop.getUserData([
                        int, str
                    ], "||\tEnter 1 to decrease number of seats or !q to cancel:\n||\t",
                                         "Wrong data")
                    if p == 1: continue
                    else:
                        exit1(username)
                        break
                else:
                    seatFlag = True
                    break

    if seatFlag:
        p = ipop.getUserData([
            str
        ], "||\tEnter S to manually select seats or any other key for automatic selection:\n||\t",
                             "Wrong data")
        if p == None:
            exit1(username)
        elif p == 'S' or p == 's':
            print("||\tAvailable seats are:")
            print(seats)
            print("||\tEnter seat numbers for " + str(n) + " reservations")
            for i in range(n):
                s = ipop.getUserData([int], "", "Wrong data", True,
                                     ['x in ' + str(seats)], True)
                if s == None:
                    exit1(username)
                bookedSeats.append(s)
        else:
            for i in range(n):
                s = seats[i]
                bookedSeats.append(s)
        seatReserveFlag = True
        print("||\tBooked seats are: " + str(bookedSeats) + '\n')

    if seatReserveFlag:
        fare = mdb.getFare(bus_id, source, destination)
        amount = n * fare
        print("||\tAll set! Total Fare = " + str(n) + " * " + str(fare) +
              " = " + str(amount))
        print("||\tPress any key to book. !q to cancel")
        p = input()
        if p == None:
            exit1(username)
        else:
            for bs in bookedSeats:
                tickets.append(
                    mdb.add_reservation(bus_id, username, source, destination,
                                        date, bs, fare) + '\t' + str(bs))

            timetable = mdb.bus_timetable(bus_id)
            for place, time in timetable:
                if source == place: ts = time
                if destination == place: te = time

            ticket_print(username, tickets, bus_id,
                         mdb.getRouteFromBusID(bus_id), source, destination,
                         date, n, amount, ts, te)