I created a code that will create, or rather build a URL based on the configuration. Everything works, however with the expansion of my project I added multiple languages etc. every section only changes very small details in the output however I copy and pasted the majority of the code. (I'm still learning and this was the only way I knew how to do it). I don't know how to get rid of the nested if statements and reuse the majority of the code. I know that I can use functions, however I can't imagine where I can begin and how they will exchange the information between themselves.
#created by Kaloian Kozlev on 10.08.2018
import replit
import time
def welcome():
choice = 0
while choice <= 5:
print(
"\nWelcome to URL Generator v3.0 VERSION
UPDATE: 31/08/2018 \n-------------------------------- -------------------------- \n\n1.Direct/Combined 2.Indirect 1. Multiple offer link added \n3.Console 4.Facebook 2. Facebook link added \n 3. Multipe language support \n5.Exit \n--------------------------------- -------------------------- "
)
try:
print("\nLanguage:\n---------\n1. English \n2. German\n3. French ")
lang = int(input("\nSelect Language: "))
#English
if lang == 1:
choice = int(input("\nSelect URL generator: "))
if choice == 1:
multiple = str(input("\nWould you like to create a multiple offer link? Y/N "))
if multiple == "y":
print("\n\nMultiple offer link\n-------------------")
cid = str(input("\nPlease enter the CID: "))
rid = int(input("Please enter the RID: "))
pid = str(input("Please enter multiple PIDs using ****,****: "))
print("\nhttps://bda.bookatable.com/?cid=" + cid + "&rid=" +
str(rid) + "&pid=" + str(pid) + "&lang=en-GB")
if multiple =="n":
print("\n\nSingle offer link\n-----------------")
cid = str(input("\nPlease enter the CID: "))
rid = int(input("Please enter the RID: "))
pid = int(input("Please enter the PID: "))
print("\nhttps://bda.bookatable.com/?cid=" + cid + "&rid=" +
str(rid) + "&pid=" + str(pid) + "&lang=en-GB")
elif choice == 2:
multiple =str(input("\nWould you like to create a multiple offer link? Y/N "))
if multiple == "y":
print("\n\nMultiple offer link\n-------------------")
rid = int(input("\nPlease enter the RID: "))
pid = str(input("Please enter multiple PIDs using ****,****: "))
print(
"\nhttps://bda.bookatable.com/?cid=INTL-LBDIRECTORY_INDIRECT:10508&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=en-GB")
if multiple == "n":
print("\n\nSingle offer link\n-----------------")
rid = int(input("\nPlease enter the RID: "))
pid = int(input("Please enter the PID: "))
print(
"\nhttps://bda.bookatable.com/?cid=INTL-LBDIRECTORY_INDIRECT:10508&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=en-GB")
elif choice == 3:
multiple =str(input("\nWould you like to create a multiple offer link? Y/N "))
if multiple == "y":
print("\n\nMultiple offer link\n-------------------")
rid = int(input("\nPlease enter the RID: "))
pid = str(input("Please enter multiple PIDs using ****,****: "))
print(
"\nhttps://bda.bookatable.com/?cid=CONSOLEEMAILCAMPAIGNS:18663&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=en-GB")
if multiple == "n":
print("\n\nSingle offer link\n-----------------")
rid = int(input("\nPlease enter the RID: "))
pid = int(input("Please enter the PID: "))
print(
"\nhttps://bda.bookatable.com/?cid=CONSOLEEMAILCAMPAIGNS:18663&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=en-GB")
elif choice == 4:
offer = str(input("\nWould you like to create an Offer or Restaurant link? O/R"))
if offer == "o":
print("\n\nFacebook offer link\n-------------------")
rid = int(input("\nPlease enter the RID: "))
pid = int(input("Please enter the PID: "))
print(
"\nhttps://bda.bookatable.com/?cid=UK-RES-FACEBOOK:24747&rid="+ str(rid)+ "&pid=" + str(pid) + "&lang=en-GB")
if offer == "r":
print("\n\nFacebook restaurant link\n------------------------")
rid = int(input("\nPlease enter the RID: "))
print(
"\nhttps://bda.bookatable.com/?cid=UK-RES-FACEBOOK:24747&rid="+ str(rid)+ "&lang=en-GB")
#German
if lang == 2:
choice = int(input("\nSelect URL generator: "))
if choice == 1:
multiple = str(input("\nWould you like to create a multiple offer link? Y/N "))
if multiple == "y":
print("\n\nMultiple offer link\n-------------------")
cid = str(input("\nPlease enter the CID: "))
rid = int(input("Please enter the RID: "))
pid = str(input("Please enter multiple PIDs using ****,****: "))
print("\nhttps://bda.bookatable.com/?cid=" + cid + "&rid=" +
str(rid) + "&pid=" + str(pid) + "&lang=de-DE")
if multiple =="n":
print("\n\nSingle offer link\n-----------------")
cid = str(input("\nPlease enter the CID: "))
rid = int(input("Please enter the RID: "))
pid = int(input("Please enter the PID: "))
print("\nhttps://bda.bookatable.com/?cid=" + cid + "&rid=" +
str(rid) + "&pid=" + str(pid) + "&lang=de-DE")
elif choice == 2:
multiple =str(input("\nWould you like to create a multiple offer link? Y/N "))
if multiple == "y":
print("\n\nMultiple offer link\n-------------------")
rid = int(input("\nPlease enter the RID: "))
pid = str(input("Please enter multiple PIDs using ****,****: "))
print(
"\nhttps://bda.bookatable.com/?cid=INTL-LBDIRECTORY_INDIRECT:10508&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=de-DE")
if multiple == "n":
print("\n\nSingle offer link\n-----------------")
rid = int(input("\nPlease enter the RID: "))
pid = int(input("Please enter the PID: "))
print(
"\nhttps://bda.bookatable.com/?cid=INTL-LBDIRECTORY_INDIRECT:10508&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=de-DE")
elif choice == 3:
multiple =str(input("\nWould you like to create a multiple offer link? Y/N "))
if multiple == "y":
print("\n\nMultiple offer link\n-------------------")
rid = int(input("\nPlease enter the RID: "))
pid = str(input("Please enter multiple PIDs using ****,****: "))
print(
"\nhttps://bda.bookatable.com/?cid=CONSOLEEMAILCAMPAIGNS:18663&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=de-DE")
if multiple == "n":
print("\n\nSingle offer link\n-----------------")
rid = int(input("\nPlease enter the RID: "))
pid = int(input("Please enter the PID: "))
print(
"\nhttps://bda.bookatable.com/?cid=CONSOLEEMAILCAMPAIGNS:18663&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=de-DE")
elif choice == 4:
offer = str(input("\nWould you like to create an Offer or Restaurant link? O/R"))
if offer == "o":
print("\n\nFacebook offer link\n----be created with min - ---------------")
rid = int(input("\nPlease enter the RID: "))
pid = int(input("Please enter the PID: "))
print(
"\nhttps://bda.bookatable.com/?cid=UK-RES-FACEBOOK:24747&rid="+ str(rid)+ "&pid=" + str(pid) + "&lang=de-DE")
if offer == "r":
print("\n\nFacebook restaurant link\n------------------------")
rid = int(input("\nPlease enter the RID: "))
print(
"\nhttps://bda.bookatable.com/?cid=UK-RES-FACEBOOK:24747&rid="+ str(rid)+ "&lang=de-DE")
#French
if lang == 3:
choice = int(input("\nSelect URL generator: "))
if choice == 1:
multiple = str(input("\nWould you like to create a multiple offer link? Y/N "))
if multiple == "y":
print("\n\nMultiple offer link\n-------------------")
cid = str(input("\nPlease enter the CID: "))
rid = int(input("Please enter the RID: "))
pid = str(input("Please enter multiple PIDs using ****,****: "))
print("\nhttps://bda.bookatable.com/?cid=" + cid + "&rid=" +
str(rid) + "&pid=" + str(pid) + "&lang=fr-FR")
if multiple =="n":
print("\n\nSingle offer link\n-----------------")
cid = str(input("\nPlease enter the CID: "))
rid = int(input("Please enter the RID: "))
pid = int(input("Please enter the PID: "))
print("\nhttps://bda.bookatable.com/?cid=" + cid + "&rid=" +
str(rid) + "&pid=" + str(pid) + "&lang=fr-FR")
elif choice == 2:
multiple =str(input("\nWould you like to create a multiple offer link? Y/N "))
if multiple == "y":
print("\n\nMultiple offer link\n-------------------")
rid = int(input("\nPlease enter the RID: "))
pid = str(input("Please enter multiple PIDs using ****,****: "))
print(
"\nhttps://bda.bookatable.com/?cid=INTL-LBDIRECTORY_INDIRECT:10508&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=fr-FR")
if multiple == "n":
print("\n\nSingle offer link\n-----------------")
rid = int(input("\nPlease enter the RID: "))
pid = int(input("Please enter the PID: "))
print(
"\nhttps://bda.bookatable.com/?cid=INTL-LBDIRECTORY_INDIRECT:10508&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=fr-FR")
elif choice == 3:
multiple =str(input("\nWould you like to create a multiple offer link? Y/N "))
if multiple == "y":
print("\n\nMultiple offer link\n-------------------")
rid = int(input("\nPlease enter the RID: "))
pid = str(input("Please enter multiple PIDs using ****,****: "))
print(
"\nhttps://bda.bookatable.com/?cid=CONSOLEEMAILCAMPAIGNS:18663&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=fr-FR")
if multiple == "n":
print("\n\nSingle offer link\n-----------------")
rid = int(input("\nPlease enter the RID: "))
pid = int(input("Please enter the PID: "))
print(
"\nhttps://bda.bookatable.com/?cid=CONSOLEEMAILCAMPAIGNS:18663&rid="
+ str(rid) + "&pid=" + str(pid) + "&lang=fr-FR")
elif choice == 4:
offer = str(input("\nWould you like to create an Offer or Restaurant link? O/R"))
if offer == "o":
print("\n\nFacebook offer link\n-------------------")
rid = int(input("\nPlease enter the RID: "))
pid = int(input("Please enter the PID: "))
print(
"\nhttps://bda.bookatable.com/?cid=UK-RES-FACEBOOK:24747&rid="+ str(rid)+ "&pid=" + str(pid) + "&lang=fr-FR")
if offer == "r":
print("\n\nFacebook restaurant link\n------------------------")
rid = int(input("\nPlease enter the RID: "))
print(
"\nhttps://bda.bookatable.com/?cid=UK-RES-FACEBOOK:24747&rid="+ str(rid)+ "&lang=fr-FR")
elif choice == 5:
replit.clear()
print("\n\nProgram terminated")
return
else:
print("\nWrong selection, please choose options 1-5")
time.sleep(2)
replit.clear()
welcome()
end = input("\nWould you like to continue Y/N ")
if end == "y":
replit.clear()
welcome()
if end == "n":
replit.clear()
print("\n\nProgram terminated")
return
elif end == "":
replit.clear()
print("\n\nProgram terminated")
return
except ValueError:
print("\nPlease enter a number!")
time.sleep(1)
replit.clear()
welcome()