Untitled

Code of Python
 avatar
unknown
abc
4 years ago
2.7 kB
7
Indexable
from tkinter import *
import sqlite3
import tkinter.messagebox
import csv


class Booking(object):
    def __init__(self, booking_id, pickup_time, pickup_location, destination, num_of_passengers, car_id, client_id,
                 status):
        self.booking_id = booking_id
        self.pickup_time = pickup_time
        self.pickup_location = pickup_location
        self.destination = destination
        self.num_of_passengers = num_of_passengers
        self.car_id = car_id
        self.client_id = client_id
        self.status = status


    def display_info(self):
        print(self.booking_id)
        print(self.pickup_time)
        print(self.pickup_location)
        print(self.destination)
        print(self.num_of_passengers)
        print(self.car_id)
        print(self.client_id)
        print(self.status)

booking1 = Booking(1, 24, 'Warsaw', 'Go to friends', 2, 1, 1, 1)

booking1.display_info()

def add_booking():
        #Open csv file at start
    outfile = open('newBooking.csv', 'a', newline='')
    w = csv.writer(outfile)  # Need to write the user input to the .csv file.

    #Everything wrapped in a while True loop, you can change to any loop accordingly
    while True:
        booking_id = input("Enter booking ID #: ")  # Generate data for each column to fill in to the output file.
        pickup_time = input("Enter pickup time: ")  # Each line asks the user to add data do the line.
        pickup_location = input("Enter pickup location: ")
        destination = input("Enter destination: ")
        num_of_passengers = input("Enter number of passengers: ")
        car_id= input("Enter car ID: ")
        client_id = input("Enter Client ID: ")
        status = input("Enter status of new booking: ")
        print(booking_id, pickup_time, pickup_location, destination, num_of_passengers, car_id, client_id, status)  # Prints the line of user data
        input4 = input("Append to booking list? Y/N")  # Asks user to append the data to the output file.
        if input4.lower() == "y":
            w.writerow([booking_id, pickup_time, pickup_location, destination, num_of_passengers, car_id, client_id, status])  # <-This is the portion that seems to fall apart.
            print("New booking has been added success1fully")
            outfile.close()
            exit()
        if input4.lower() == "n":
            print("SKIPPING. RESTARTING....")
        #If you see stop, stop writing, close the file and exit
        if input4.lower() == 'stop':
            print('Not writing anymore! Stopping')
            outfile.close()
            exit()
        else:
            print("Invalid entry restarting program.")

add_booking()
Editor is loading...