示例#1
0
    def query(self):
        print('------------机票查询-------------')
        data = []  # 文件中的数据存放之处
        file = open(".vscode\\keshe\\tickets.txt", "r", encoding='utf-8')
        file.readline()  # readline进行读文件时第一行是数据表中的列,可以将文件移到第二行开始处
        for line in file:  # 实现了将文件信息全部读入列表data中,列表中的一个元素即是一个对象(在这里是机票对象)
            if line != '\n':
                lines = line.strip('\n').split(" ")
                # print(lines)
                obj = Ticket(lines[0], lines[1], lines[2], lines[3], lines[4],
                             lines[5], lines[6], lines[7], lines[8], lines[9],
                             lines[10], lines[11])
                data.append(obj)
        # Print(data)

        a = int(input('输入查询条件:1、两城市间航班情况  2、航班班号  3、航空公司名称->> '))
        while ((a != 1) and (a != 2) and (a != 3)):
            a = input('请重新输入查询条件:>> ')
        if a == 1:  ############## 若两城市之间无直飞航班,设计算法提供转机航班 这个先不做了555
            b = input('输入起始城市->> ')
            c = input('输入终点城市->> ')
            for x in data:
                if ((x.takeoff_place == b) and (x.land_place == c)):
                    Print(x)
        elif a == 2:  ########### 有待补充其他查询条件
            d = input('输入航班号->> ')
            for x in data:
                if (x.id == d):
                    Print(x)
                    break
        elif a == 3:
            d = input('输入航空公司名称 ->> ')
            for x in data:
                if (x.company_name == d):
                    Print(x)
示例#2
0
 def query(self):
     print('------------机票查询-------------')
     data = []  # 文件中的数据存放之处
     Data = []  # 按城市查找时符合条件的先存到这里
     file = open(".vscode\\keshe\\tickets.txt", "r", encoding='utf-8')
     file.readline()   # readline进行读文件时第一行是数据表中的列,可以将文件移到第二行开始处
     for line in file:  # 实现了将文件信息全部读入列表data中,列表中的一个元素即是一个对象(在这里是机票对象)
         if line != '\n':
             lines = line.strip('\n').split(" ")
             # print(lines)
             obj = Ticket(lines[0], lines[1], lines[2], lines[3], lines[4], lines[5], lines[6], lines[7], lines[8], lines[9], lines[10], lines[11])
             data.append(obj)
     # Print(data)
     Data.append(data[0])
     
     a = int(input('输入查询条件:1、两城市间航班情况  2、指定航班号航班情况 ->> '))
     while((a != 1) and (a != 2)):
         a = input('请重新输入查询条件:>> ')
     if(a == 1): ############## 若两城市之间无直飞航班,设计算法提供转机航班 这个先不做了555
         b = input('输入起始城市->> ') 
         c = input('输入终点城市->> ')
         for i in range(0, len(data)):
             if ((data[i].takeoff_place == b) and (data[i].land_place == c)):
                 Data.append(data[i])
         # for x in Data:
         #     Print(x)
         if len(Data) > 1:
             print('-------------排序输出--------------')
             recommend(Data)
     else: ########### 有待补充其他查询条件
         d = input('输入航班号->> ')
         for x in data:
             if(x.id == d):
                 Print(x)
                 break
示例#3
0
 def change(
     self
 ):  ## 单独拿出来了延期和取消的话,那这个修改航班的功能不就被抢的差不多了就  有待商榷   还是应该可以改时间的,因为时间也可以提前的
     print('-------------------修改航班------------------')
     data = []
     Id = input('输入所要修改航班的班号:')
     attribute = input(
         '输入所要修改的属性:1.起飞时间 2.起飞地点 3.降落时间 4.降落地点 5.余票 6.票价 7.经停站1名称 8.到达经停站1时间 9.经停站2名称 10.到达经停站2时间 =>> '
     )
     value = input('输入修改后的值:')
     file = open(".vscode\\keshe\\tickets.txt", "r", encoding='utf-8')
     file.readline()
     for line in file:
         lines = line.strip('\n').split(' ')
         # print(lines)
         if len(lines) > 1:  ## 专为处理空行的情况
             obj = Ticket(lines[0], lines[1], lines[2], lines[3], lines[4],
                          lines[5], lines[6], lines[7], lines[8], lines[9],
                          lines[10], lines[11])
             data.append(obj)
     file.close()
     for i in range(0, len(data)):
         if data[i].id == Id:
             if attribute == '1':
                 data[i].takeoff_time = value
             elif attribute == '2':
                 data[i].takeoff_place = value
             elif attribute == '3':
                 data[i].land_time = value
             elif attribute == '4':
                 data[i].land_place = value
             elif attribute == '5':
                 data[i].number = value
             elif attribute == '6':
                 data[i].price = value
             elif attribute == '7':
                 data[i].stop1_place = value
             elif attribute == '8':
                 data[i].stop1_time = value
             elif attribute == '9':
                 data[i].stop2_place = value
             elif attribute == '10':
                 data[i].stop2_time = value
             break
     file = open(".vscode\\keshe\\tickets.txt", "w", encoding='utf-8')
     file.write(
         '航班编号 航空公司名称 起飞时间 起飞地点 降落时间 降落地点 余票 票价 经停站1名称 到达经停站1时间 经停站2名称 到达经停站2时间\n'
     )
     for line in data:
         file.write(
             '%s\n' %
             (line.id + ' ' + line.company_name + ' ' + line.takeoff_time +
              ' ' + line.takeoff_place + ' ' + line.land_time + ' ' +
              line.land_place + ' ' + line.number + ' ' + line.price + ' ' +
              line.stop1_place + ' ' + line.stop1_time + ' ' +
              line.stop2_place + ' ' + line.stop2_time))
     print('航班修改成功!')
示例#4
0
    def buy(self):
        print('-------------机票购买-------------')
        data = []
        ticket_id = input('请输入航班号: ')
        file = open(".vscode\\keshe\\tickets.txt", "r", encoding='utf-8')
        file.readline()
        for line in file:
            if line != '\n':
                lines = line.strip('\n').split(" ")
                # print(lines)
                obj = Ticket(lines[0], lines[1], lines[2], lines[3], lines[4], lines[5], lines[6], lines[7], lines[8], lines[9], lines[10], lines[11])
                data.append(obj)
        for x in data:
            if x.id == ticket_id:
                if int(x.number) > 0:
                    x.number = int(x.number) - 1
                    break
                else:
                    return ticket_id
        # print(data[0].number)
        file.close()

        # for x in data:
        #     # Print(x)
        #     x = x.id + ' ' + x.company_name + ' ' + x.takeoff_time + ' ' + x.takeoff_place + ' ' + x.land_time + ' ' + x.land_place + ' ' + str(x.number)
        #     # print(x)
        file = open(".vscode\\keshe\\tickets.txt", "w", encoding='utf-8')
        file.write('航班编号 航空公司名称 起飞时间 起飞地点 降落时间 降落地点 余票 票价 经停站1名称 到达经停站1时间 经停站2名称 到达经停站2时间\n')
        for x in data:
            # 你要把那一大长串字符串作为一次一行的输入,所以要加括号。
            file.write('%s\n' %(x.id + ' ' + x.company_name + ' ' + x.takeoff_time + ' ' + x.takeoff_place + ' ' + x.land_time + ' ' + x.land_place + ' ' + str(x.number)
                                 + ' ' +  x.price + ' ' + x.stop1_place + ' ' + x.stop1_time + ' ' + x.stop2_place + ' ' + x.stop2_time))
        print('机票购买成功!')
        file.close()
        
        # 在用户数据库中把他刚刚买的票给添上
        data = []
        file = open(".vscode\\keshe\\customers.txt", "r", encoding='utf-8')
        file.readline()
        for line in file:
            if line != '\n':
                lines = line.strip('\n').split(' ')
                obj = CUSTOMER(lines[0], lines[1], lines[2], lines[3], lines[4], lines[5])
                data.append(obj)
        file.close()
        # 应该再找出是谁要进行购买,也就是当前的操作对象是谁。
        for x in data:
            if x.account == self.account:
                x.had = ticket_id
                break
        file = open(".vscode\\keshe\\customers.txt", "w", encoding='utf-8')
        file.write('姓名 账号 密码 邮箱 已到手的机票 已预订的机票\n')
        for x in data:
            file.write('%s\n' %(x.name + ' ' + x.account + ' ' + x.password + ' ' + x.email + ' ' + x.had + ' ' + x.reserved))

        return 0
示例#5
0
    def late(self):
        print('-------------------推迟航班------------------')
        data = []
        takeoff_place = ''
        takeoff_time = ''
        land_place = ''
        land_time = ''
        Id = input('输入要延期航班的班号:')
        # Time2 = input('输入延期到达时间:')
        file = open(".vscode\\keshe\\tickets.txt", "r", encoding='utf-8')
        file.readline()
        for line in file:
            lines = line.strip('\n').split(' ')
            # print(lines)
            ###########################################
            if len(lines) > 1:  ## 专为处理空行的情况###  好像也不用,因为空行没空格? ? ?
                ###########################################
                obj = Ticket(lines[0], lines[1], lines[2], lines[3], lines[4],
                             lines[5], lines[6], lines[7], lines[8], lines[9],
                             lines[10], lines[11])
                data.append(obj)
        file.close()
        for x in data:
            if x.id == Id:
                takeoff_time = x.takeoff_time
                takeoff_place = x.takeoff_place
                land_time = x.land_time
                land_place = x.land_place

                x.takeoff_time = input('输入延期起飞时间:')
                x.land_time = input('输入延期到达时间:')
                if x.stop1_time != '0':
                    x.stop1_time = input('输入经停站1的到达时间:')
                if x.stop2_time != '0':
                    x.stop2_time = input('输入经停站2的到达时间:')
                break
        file = open(".vscode\\keshe\\tickets.txt", "w", encoding='utf-8')
        file.write(
            '航班编号 航空公司名称 起飞时间 起飞地点 降落时间 降落地点 余票 票价 经停站1名称 到达经停站1时间 经停站2名称 到达经停站2时间\n'
        )
        for line in data:
            file.write(
                '%s\n' %
                (line.id + ' ' + line.company_name + ' ' + line.takeoff_time +
                 ' ' + line.takeoff_place + ' ' + line.land_time + ' ' +
                 line.land_place + ' ' + line.number + ' ' + line.price + ' ' +
                 line.stop1_place + ' ' + line.stop1_time + ' ' +
                 line.stop2_place + ' ' + line.stop2_time))
        print('航班推延操作成功!')
        file.close()
        ### 延期的话最终还要通知乘坐该航班的乘客延期了 ~  还得推荐个航班
        qifei = recommend(takeoff_place, land_place, takeoff_time, land_time)
        infor(Id, 'late', qifei)
示例#6
0
 def delete(self):  # 同时也是航班的取消操作吗 ????
     print('-------------------删除航班------------------')
     data = []
     takeoff_place = ''
     land_place = ''
     takeoff_time = ''
     land_time = ''
     Id = input('输入所要取消航班的班号:')
     file = open(".vscode\\keshe\\tickets.txt", "r", encoding='utf-8')
     file.readline()
     for line in file:
         if line != '\n':
             lines = line.strip('\n').split(' ')
             obj = Ticket(lines[0], lines[1], lines[2], lines[3], lines[4],
                          lines[5], lines[6], lines[7], lines[8], lines[9],
                          lines[10], lines[11])
             data.append(obj)
     file.close()
     # print(len(data))
     for i in range(0, len(data)):
         if data[i].id == Id:
             # del data[i]
             if i < len(data):
                 takeoff_time = data[i].takeoff_time
                 takeoff_place = data[i].takeoff_place
                 land_time = data[i].land_time
                 land_place = data[i].land_place
                 del data[i]
             ###### what, why can't delete the last element ? why why why why why why why why why why why why why
             break  #### I have found the reasons ~~~ for...
     file = open(".vscode\\keshe\\tickets.txt", "w", encoding='utf-8')
     file.write(
         '航班编号 航空公司名称 起飞时间 起飞地点 降落时间 降落地点 余票 票价 经停站1名称 到达经停站1时间 经停站2名称 到达经停站2时间\n'
     )
     for line in data:
         file.write(
             '%s\n' %
             (line.id + ' ' + line.company_name + ' ' + line.takeoff_time +
              ' ' + line.takeoff_place + ' ' + line.land_time + ' ' +
              line.land_place + ' ' + line.number + ' ' + line.price + ' ' +
              line.stop1_place + ' ' + line.stop1_time + ' ' +
              line.stop2_place + ' ' + line.stop2_time))
     print('航班删除成功!')
     ### 航班删除成功之后还要通知乘坐该航班的乘客 ~  还得推荐个航班
     qifei = recommend(takeoff_place, land_place, takeoff_time, land_time)
     infor(Id, 'delete', qifei)
示例#7
0
def recommend(takeoff_place, land_place, takeoff_time, land_time):
    data = []
    Data = []
    file = open(".vscode\\keshe\\tickets.txt", "r", encoding='utf-8')
    file.readline()
    for line in file:
        if line != '\n':
            lines = line.strip('\n').split(" ")
            obj = Ticket(lines[0], lines[1], lines[2], lines[3], lines[4],
                         lines[5], lines[6], lines[7], lines[8], lines[9],
                         lines[10], lines[11])
            data.append(obj)

    for i in range(0, len(
            data)):  # 这里的处理其实应该是提前到达的航班也行的!同时排除时间地点相同到达时间也不延误但是不和被取消航班在同一天的航班
        if ((time_trans(data[i].takeoff_time)[1]
             == time_trans(takeoff_time)[1])
                and (data[i].takeoff_place == takeoff_place)
                and (data[i].land_place == land_place)
                and ((int(time_trans(data[i].land_time)[2]) -
                      int(time_trans(land_time)[2])) * 60 +
                     (int(time_trans(data[i].land_time)[3]) -
                      int(time_trans(land_time)[3])) <= 0)):
            Data.append(data[i])
    if len(Data) == 0:
        return "好自为之吧,没有很合适的航班。"

    now = datetime.datetime.now()
    now_hour = now.hour
    now_minute = now.minute
    min_ticket = ' '
    minzhi = 1000000
    for x in Data:
        x_hour = int(time_trans(x.takeoff_time)[2])
        x_minute = int(time_trans(x.takeoff_time)[3])
        delt = (x_hour - now_hour) * 60 + (x_minute - now_minute)
        if minzhi > delt:
            minzhi = delt
            min_ticket = x.id
    return min_ticket