我有2个CSV和JSON文件:
name, start_time, end_time
Michał Najman, 23.03.2023 14:00, 23.03.2023 15:00
Marcin Wiśniewski, 23.03.2023 17:00, 23.03.2023 18:00
Tadeusz Stockinger, 24.03.2023 11:00, 24.03.2023 12:30
Robert Brzozowski, 24.03.2023 12:30, 24.03.2023 14:00
Norman Dudziuk, 24.03.2023 16:30, 24.03.2023 17:00
Klaus Sevkovic, 25.03.2023 14:00, 25.03.2023 14:30
Paweł Gulczyński, 26.03.2023 12:00, 26.03.2023 13:30
Mieczysław Okniński, 26.03.2023 13:30, 26.03.2023 14:00
Json:
{"23.03": [{
"name": "Michał Najman",
"start_time": "14:00",
"end_time": "15:00"
},
{"name": "Marcin Wiśniewski",
"start_time": "17:00",
"end_time": "18:00"
}],
"24.03": [{
"name": "Tadeusz Stockinger",
"start_time": "11:00",
"end_time": "12:30"
},
{"name": "Robert Brzozowski",
"start_time": "12:30",
"end_time": "14:00"
},
{"name": "Norman Dudziuk",
"start_time": "16:30",
"end_time": "17:00"
}],
"25.03": [{
"name": "Klaus Sevkovic",
"start_time": "14:00",
"end_time": "14:30"
}],
"26.03": [{
"name": "Paweł Gulczyński",
"start_time": "12:00",
"end_time": "13:30"
},
{"name": "Mieczysław Okniński",
"start_time": "13:30",
"end_time": "14:00"
}],
"27.03": [],
"28.03": [],
"29.03": [],
"30.03": []
}
我试着检查JSON文件中的时间是否可用,如果用户选择的时间不可用,程序应该建议下一个时间,例如:您想预订16:00的房间吗?答案:(是/否)
如果用户选择No,请返回上一步。我正在阅读一个JSON文件,并尝试检查我想要的时间是否可用,如果没有,则我会问用户是否要预订下午4点?(yes/no)#如果用户选择No,请返回上一步。
import json
class Make_aReservation:
# print('$ Make a reservation ')
# name = input("What's your Name?\n")
book = input("When would you like to book? {DD.MM.YYYY HH:MM}\n")
def __init__(self):
self.filename = '23.03-30.03.json'
def file_to_text(self):
with open(self.filename, "r") as file_opened:
text = json.load(file_opened)
return text
def reservation(self):
# print(self.file_to_text())
if self.book[:5] in self.file_to_text():
# print(self.file_to_text()[self.book[:5]])
# print(self.file_to_text()[self.book[:5]])
for i in self.file_to_text()[self.book[:5]]:
print(i)
print(self.book[11:16])
if self.book[11:16] in i['end_time']:
print(True)
else:
print(False)
make_aReservation = Make_aReservation()
print(make_aReservation.reservation())
输出:
When would you like to book? {DD.MM.YYYY HH:MM}
23.03.2023 15:00
{'name': 'Michał Najman', 'start_time': '14:00', 'end_time': '15:00'}
15:00
True
{'name': 'Marcin Wiśniewski', 'start_time': '17:00', 'end_time': '18:00'}
15:00
False
None
Process finished with exit code 0
如何检查这样的JSON文件是否已经预订?
1条答案
按热度按时间bxgwgixi1#