2015-04-04 14:11:55 +02:00
|
|
|
from app import db
|
2019-01-21 18:15:13 +01:00
|
|
|
import add_oceans_garden, add_admins, add_simpizza, add_primadonna
|
2015-04-04 14:11:55 +02:00
|
|
|
|
|
|
|
|
2019-01-21 18:15:13 +01:00
|
|
|
entry_sets = {"Admins": add_admins.add, "Ocean's Garden": add_oceans_garden.add, "SimPizza": add_simpizza.add, "Primadonna": add_primadonna.add}
|
2015-04-04 14:11:55 +02:00
|
|
|
yes = ["yes", "y", "Y"]
|
|
|
|
no = ["no", "n", "N"]
|
|
|
|
|
|
|
|
|
|
|
|
# Commit all the things
|
|
|
|
def commit():
|
|
|
|
db.session.commit()
|
|
|
|
print("Committing successful")
|
|
|
|
|
|
|
|
|
|
|
|
def check_if_overwrite():
|
2018-03-09 00:59:14 +01:00
|
|
|
answer = input("Do you want to overwrite the previous database? (y/N) ")
|
2015-04-04 14:11:55 +02:00
|
|
|
return answer in yes
|
|
|
|
|
|
|
|
|
|
|
|
def add_all():
|
2015-04-04 14:26:09 +02:00
|
|
|
for entry_set in entry_sets.keys():
|
|
|
|
print("Adding {}.".format(entry_set))
|
|
|
|
entry_sets[entry_set]()
|
2015-04-04 14:11:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
def recreate_from_scratch():
|
2018-03-08 23:22:51 +01:00
|
|
|
confirmation = "Are you very very sure? (Will delete previous entries!) (y/N) "
|
2015-04-04 14:11:55 +02:00
|
|
|
check = "I acknowledge any repercussions!"
|
2018-03-09 00:59:14 +01:00
|
|
|
if input(confirmation) in yes and input("Type: '{}' ".format(check)) == check:
|
2015-05-13 13:34:32 +02:00
|
|
|
print("Resetting the database!")
|
|
|
|
db.drop_all()
|
|
|
|
db.create_all()
|
|
|
|
add_to_current()
|
2015-04-04 14:11:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
def add_to_current():
|
2015-04-04 14:26:09 +02:00
|
|
|
available = [entry_set for entry_set in entry_sets]
|
2015-04-04 14:11:55 +02:00
|
|
|
|
|
|
|
def add_numbers():
|
|
|
|
return " ".join(["{}({}), ".format(loc, i) for i, loc in enumerate(available)]).rstrip(", ")
|
|
|
|
|
2018-03-09 00:59:14 +01:00
|
|
|
while input("Do you still want to add something? (Y/n) ") not in no:
|
2019-01-21 18:15:13 +01:00
|
|
|
print("What do you want to add? (Use numbers, or A for all, or C for cancel) ")
|
2018-03-09 00:59:14 +01:00
|
|
|
answer = input("Available: {} : ".format(add_numbers()))
|
2015-04-04 14:11:55 +02:00
|
|
|
if answer == "A":
|
|
|
|
add_all()
|
2015-05-13 13:34:32 +02:00
|
|
|
available = []
|
2015-04-04 14:11:55 +02:00
|
|
|
elif answer == "C":
|
|
|
|
pass
|
|
|
|
elif answer in [str(x) for x in range(len(available))]:
|
|
|
|
answer = int(answer)
|
|
|
|
print("Adding {}.".format(available[answer]))
|
2015-04-04 14:26:09 +02:00
|
|
|
entry_sets[str(available[answer])]()
|
2015-04-04 14:11:55 +02:00
|
|
|
del available[answer]
|
|
|
|
else:
|
|
|
|
print("Not a valid answer.")
|
|
|
|
print("Thank you for adding, come again!")
|
|
|
|
|
|
|
|
|
|
|
|
def init():
|
|
|
|
print('Database modification script!')
|
|
|
|
print('=============================\n\n')
|
|
|
|
if check_if_overwrite():
|
|
|
|
recreate_from_scratch()
|
|
|
|
else:
|
|
|
|
add_to_current()
|
2015-04-04 14:36:19 +02:00
|
|
|
commit()
|
2015-04-04 14:11:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
init()
|