My program generates URLs. It takes in 3 variables and substitutes them in a URL to create different working URLs. It also has 3 options for language selection, which change the language of the page to which the URL points.
However, the more options I add the more copy - pasted code there is. I know there is a way to simplify the code and only add the changes, however I'm still new to Python and I'm not too sure how.
#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("\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:
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")
#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:
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")
#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:
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")
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()
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()
(This code is also in repl.it.)