username = ""
password = ""
# Keep one load_data function
def load_data(file_name):
data = []
with open(file_name, 'r') as file:
for line in file:
line = line.strip() # Remove any trailing newline characters
if line: # Skip empty lines
# Assuming fields are comma-separated
fields = line.split(',')
data.append(fields)
return data
def login_menu():
while True:
print("======= Welcome Back =======\n")
print("---------Login----------------\n")
username = input("Enter username: ")
password = input("Enter Password: ")
# print(username)
# print(password)
data = load_data('users.txt') # data is a list of [username, password]
pairs
login_successful = False
for user in data:
if user[1] == username and user[2] == password: # Fix indexing
print("Login Successful...!!!\n")
login_successful = True
main_menu(user) # Pass user data to main_menu
break
if not login_successful:
print("Username or Password is Incorrect\n")
def logout():
print("....Logging out...\n")
username = ""
password = ""
login_menu()
# Promotions
# Function to save promotions
def save_promotions(filename, promotions):
with open(filename, 'w') as file:
for promo in promotions:
file.write(','.join(promo) + '\n')
# Function to display promotions
def view_promotions():
promotions = load_data('promotions.txt')
print("\n==== Current Trip Promotions ====\n")
if not promotions:
print("No promotions available.\n")
else:
for promo in promotions:
print(f"Destination: {promo[0]}, Discount: {promo[1]}, "
f"Valid From: {promo[2]} to {promo[3]}")
print("\n")
# Function to add a promotion
def add_promotion():
destination = input("Enter trip destination: ")
discount = input("Enter discount (e.g., 20%): ")
start_date = input("Enter start date (YYYY-MM-DD): ")
end_date = input("Enter end date (YYYY-MM-DD): ")
promotions = load_data('promotions.txt')
promotions.append([destination, discount, start_date, end_date])
save_promotions('promotions.txt', promotions)
print(f"Promotion added for {destination} with {discount} discount "
f"from {start_date} to {end_date}.\n")
# Function to remove a promotion
def remove_promotion():
view_promotions() # Show current promotions
destination = input("Enter the destination to remove promotion: ")
promotions = load_data('promotions.txt')
updated_promotions = [promo for promo in promotions if promo[0].lower() !=
destination.lower()]
if len(promotions) == len(updated_promotions):
print(f"No promotion found for destination {destination}.\n")
else:
save_promotions('promotions.txt', updated_promotions)
print(f"Promotion for {destination} removed.\n")
# Main function for managing promotions
def manage_promotions():
while True:
print("\n==== Manage Trip Promotions ====")
print("1. View Promotions")
print("2. Add Promotion")
print("3. Remove Promotion")
print("4. Back to Main Menu")
choice = input("Enter your choice: ")
if choice == "1":
view_promotions()
elif choice == "2":
add_promotion()
elif choice == "3":
remove_promotion()
elif choice == "4":
break
else:
print("Invalid choice, please try again.\n")
# Function to display trip recommendations
def view_trip_recommendations():
recommendations = load_data('recommendations.txt')
print("\n==== Trip Recommendations ====\n")
if not recommendations:
print("No recommendations available.\n")
else:
for recommendation in recommendations:
print(f"Destination: {recommendation[0]}")
print(f"Recommendation: {recommendation[1]}\n")
print("\n")
# Function to view trip recommendations based on promotions
def view_recommended_promotions():
promotions = load_data('promotions.txt')
print("\n==== Recommended Trips Based on Promotions ====\n")
if not promotions:
print("No promotions available.\n")
else:
for promo in promotions:
print(f"Destination: {promo[0]}")
print(f"Discount: {promo[1]} (Valid From: {promo[2]} to {promo[3]})\n")
print("\n")
# Main function for viewing trip recommendations
def trip_recommendations():
while True:
print("\n==== View Trip Recommendations ====")
print("1. View All Recommendations")
print("2. View Recommended Trips Based on Promotions")
print("3. Back to Main Menu")
choice = input("Enter your choice: ")
if choice == "1":
view_trip_recommendations()
elif choice == "2":
view_recommended_promotions()
elif choice == "3":
break
else:
print("Invalid choice, please try again.\n")
#
#
def save_travellers(filename, travellers):
with open(filename, 'w') as file:
for traveller in travellers:
file.write(','.join(traveller) + '\n')
# Function to block a traveller by ID
def block_traveller(traveller_id):
travellers = load_data('travellers.txt')
traveller_found = False
for traveller in travellers:
if traveller[0] == traveller_id:
if traveller[2] == "blocked":
print(f"Traveller with ID {traveller_id} is already blocked.\n")
else:
traveller[2] = "blocked"
print(f"Traveller with ID {traveller_id} has been blocked.\n")
traveller_found = True
break
if not traveller_found:
print(f"No traveller found with ID {traveller_id}.\n")
save_travellers('travellers.txt', travellers)
#
# Function to save merchant data
def save_merchants(filename, merchants):
with open(filename, 'w') as file:
for merchant in merchants:
file.write(','.join(merchant) + '\n')
# Function to view all merchants and their statuses
# def view_merchants():
# merchants = load_merchants('merchants.txt')
# print("\n==== List of Merchants ====\n")
#
# if not merchants:
# print("No merchants found.\n")
# else:
# for merchant in merchants:
# print(f"ID: {merchant[0]}, Name: {merchant[1]}, Status:
{merchant[2]}")
# print("\n")
# Function to add a new merchant
def add_merchant():
merchant_id = input("Enter new merchant ID: ")
merchant_name = input("Enter merchant name: ")
# Load existing merchants to check for duplicates
merchants = load_data('merchants.txt')
for merchant in merchants:
if merchant[0] == merchant_id:
print(f"Merchant with ID {merchant_id} already exists.\n")
return
# Add new merchant with 'active' status
merchants.append([merchant_id, merchant_name, "active"])
save_merchants('merchants.txt', merchants)
print(f"Merchant {merchant_name} (ID: {merchant_id}) has been added
successfully.\n")
# Function to block a merchant by ID
def block_merchant(merchant_id):
merchants = load_data('merchants.txt')
merchant_found = False
for merchant in merchants:
if merchant[0] == merchant_id:
if merchant[2] == "blocked":
print(f"Merchant with ID {merchant_id} is already blocked.\n")
else:
merchant[2] = "blocked"
print(f"Merchant with ID {merchant_id} has been blocked.\n")
merchant_found = True
break
if not merchant_found:
print(f"No merchant found with ID {merchant_id}.\n")
save_merchants('merchants.txt', merchants)
# Function to unblock a merchant by ID
# def unblock_merchant(merchant_id):
# merchants = load_data('merchants.txt')
# merchant_found = False
#
# for merchant in merchants:
# if merchant[0] == merchant_id:
# if merchant[2] == "active":
# print(f"Merchant with ID {merchant_id} is already active.\n")
# else:
# merchant[2] = "active"
# print(f"Merchant with ID {merchant_id} has been unblocked.\n")
# merchant_found = True
# break
#
# if not merchant_found:
# print(f"No merchant found with ID {merchant_id}.\n")
#
# save_merchants('merchants.txt', merchants)
# # Main function to manage merchants
# def manage_merchants():
# while True:
# print("\n==== Manage Merchants ====")
# # print("1. View Merchants")
# print("1. Add Merchant")
# print("2. Block Merchant")
# # print("4. Unblock Merchant")
# print("3. Back to Main Menu")
#
# choice = input("Enter your choice: ")
#
# if choice == "1":
# add_merchant()
# elif choice == "2":
# merchant_id = input("Enter merchant ID to block: ")
# block_merchant(merchant_id)
# elif choice == "3":
# break
# else:
# print("Invalid choice, please try again.\n")
#
# Example function: Manage users
def manage_users():
print("1. Block traveller")
# print("2. Unblock traveller")
print("2. Add merchant")
print("3. Block merchant")
choice = input("Enter your choice: ")
if choice == "1":
traveller_id = input("Enter traveller ID: ")
block_traveller(traveller_id)
elif choice == "2":
# merchant_id = input("Enter merchant ID: ")
add_merchant()
elif choice == "3":
merchant_id = input("Enter merchant ID: ")
block_merchant(merchant_id)
else:
print("Invalid choice.\n")
def main_menu(user):
while True:
print(f"\n======== Admin: {user[0]} ========\n") # Print username
print("1. Manage Users")
print("2. Manage Promotions")
print("3. View Trip Recommendations")
print("4. Logout")
choice = input("Enter your choice: ")
if choice == "1":
manage_users()
elif choice == "2":
manage_promotions() # Placeholder function
elif choice == "3":
trip_recommendations() # Placeholder function
elif choice == "4":
logout() # Placeholder function
break
else:
print("Invalid choice, please try again.\n")
# Start the login menu
login_menu()