def install_wizard(): """ Runs a command-line series of prompt to gather proper paramaters and then creates the database """ # Check if SQLlite database file already exists if path.isfile('database.db'): overwrite = input( "The database file already exists. Would you like to discard it and start over?\nWARNING: This will delete the entire grant archive.\n(y/n): " ) if overwrite == 'n': # Exit if overwriting denied print("No chages made. Exiting.") exit() elif overwrite == 'y': # Backup old databse file and continue if overwriting accepted timestamp = datetime.now().strftime("%Y-%m-%d_%H:%M:%S") backup = "database_" + timestamp + ".db.bak" rename('database.db', backup) print("Old database backed up to file '" + backup + "'.") else: # Exit on invalid input print("Invalid Input. No Changes were made. Exiting.") exit("Input Error") # Prompt user for council number council = input( "Council Number (e.g. '35' for 35th Undergraduate Council): ") if not council.isdigit() or not int(council) in range(0, 100): print( 'Error: Council Number must be a 1-2 digit positive number.\nNo changes were made. Exiting.' ) exit("Input Error") # Promt user for semester semester = input("Current Semester ('F' for fall or 'S' for spring): ") if semester != 'S' and semester != 'F': print( "Error: Semester input must be either an 'S' or 'F'.\nNo changes were made. Exiting." ) exit("Input Error") # Prompt User for Current Grant Week in Semester week = input( "Grant Week in Semester (e.g. '1' for beginning of semester): ") if not week.isdigit() or not int(week) in range(1, 100): print( 'Error: Grant Week must be a 1-2 digit positive number.\nNo changes were made. Exiting.' ) exit("Input Error") # Prompt User for Weekly Default Budget budget = input("Default Weekly Budget: ") if not week.isdigit() or not int(week) > 0: print( 'Error: Default weekly budget must be a postitive whole number.\nNo changes were made. Exiting.' ) exit("Input Error") # Prompt user for admin email address to create admin user account email = input("Administrator Email: ") if not email: print( 'Error: Must enter an email address.\nNo changes were made. Exiting.' ) exit("Input Error") # Prompt user for admin first name to create admin user account first_name = input("Administrator First Name: ") if not first_name: print( 'Error: Must enter a first name.\nNo changes were made. Exiting.') exit("Input Error") # Prompt user for admin first name to create admin user account last_name = input("Administrator Last Name: ") if not last_name: print('Error: Must enter a last name.\nNo changes were made. Exiting.') exit("Input Error") # Prompt user for admin password to create admin user account password = getpass("Administrator Password: "******"Input Error") password_verify = getpass("Verify Password: "******"Input Error") # Prompt user for email account username print("Note: Application assumes Google as email account host server") grants_email_username = input("Grants Email Account Username: "******"Input Error") # Prompt user for email account password grants_email_password = getpass("Grants Email Account Password: "******"Input Error") # Prompt user for email account username print("Note: Application assumes Google as email account host server") treasurer_email_username = input("Treasurer Email Account Username: "******"Input Error") # Prompt user for email account password treasurer_email_password = getpass("Treasurer Email Account Password: "******"Input Error") # Prompt user for email account password server_name = input( "Server Name for building URLs (exclude 'http://' and '/'): ") if not server_name: print( 'Error: Must enter a server name.\nNo changes were made. Exiting.') exit("Input Error") # Prompt user for treasurer name treasurer_name = input("Treasurer's name: ") if not treasurer_name: print( 'Error: Must enter a treasurer name.\nNo changes were made. Exiting.' ) exit("Input Error") # Set application context for SQLAlchemy db.init_app(app) db.app = app # Create all database with all tables db.create_all() # Add security key configuration sec_key = Config('security_key', 'ZmL1kNBW1i') db.session.add(sec_key) # Add Council Number to config council_semester = Config('council_semester', council + semester) db.session.add(council_semester) # Add Grant Week to config grant_week = Config('grant_week', week) db.session.add(grant_week) # Add Default Weekly Budget default_budget = Config('default_budget', budget) db.session.add(default_budget) # Add Grants Email Account Username grants_email_username_db = Config('grants_email_username', grants_email_username) db.session.add(grants_email_username_db) # Add Grants Email Account Password grants_email_password_db = Config('grants_email_password', grants_email_password) db.session.add(grants_email_password_db) # Add Treasurer Email Account Username treasurer_email_username_db = Config('treasurer_email_username', treasurer_email_username) db.session.add(treasurer_email_username_db) # Add Treasurer Email Account Password treasurer_email_password_db = Config('treasurer_email_password', treasurer_email_password) db.session.add(treasurer_email_password_db) # Add Server Name server_name_db = Config('server_name', server_name) db.session.add(server_name_db) # Default to enabling email without asking user enable_email = Config('enable_email', '1') db.session.add(enable_email) # Add treasurer's name treasurer_name = Config('treasurer_name', treasurer_name) db.session.add(treasurer_name) # Add empty number of Grants for current week grants_week = Grants_Week(council + semester + '-' + week) grants_week.budget = budget db.session.add(grants_week) # Add administrator user account admin = create_user(email, first_name, last_name, password, True) db.session.add(admin) # Commit changes to databse db.session.commit() # Print success message print( "Successfully installed program configuration. Please run flask application to enable the website." )
from database_models import db from database_models import Team from database_models import * db.drop_all() db.create_all() session = getSession() class SPI: off_rating = None def_rating = None rating = None def __init__(self, rating, off_rating, def_rating): self.off_rating = off_rating self.def_rating = def_rating self.rating = rating # the contents of this class will be split into different database tables class CompactTeamData: name = None country_code = None ELO = None group = None FIFA = None Value = None # value in euro Age = None # avg. age HA = 0.0 # home advantage spi = None
def create_database(): """ Create the database file. """ if not os.path.exists('itemsCatalog.db'): db.create_all()
def create_database(): """ Create the database file. """ db.create_all()
app.config[ "SQLALCHEMY_DATABASE_URI"] = "sqlite:///database/remote_door_lock.db" else: raise Exception(f"invalid DATABASE_TYPE {DATABASE_TYPE}") app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False if INSECURE: CORS(app, supports_credentials=True) else: app.config["SESSION_COOKIE_SECURE"] = True CORS(app, resources={r"/*": {"origins": FRONTEND_URL}}) db.init_app(app) with app.app_context(): db.create_all() Session(app) # all error pages are now JSON instead of HTML @app.errorhandler(HTTPException) def handle_exception(e): response = e.get_response() response.data = json.dumps( APIResponse(code=e.code, name=e.name, description=e.description, response={}).__dict__)