Skip to content

Instantly share code, notes, and snippets.

View The-Final-Apex's full-sized avatar
💀
sadge

IOav Moykica The-Final-Apex

💀
sadge
  • Arctic
View GitHub Profile
@The-Final-Apex
The-Final-Apex / app.py
Created November 24, 2025 10:37
Update ages in a database when date of birth is given every day at midnight
def update_children_ages():
today = date.today()
kids = Kid.query.all()
for kid in kids:
if kid.date_of_birth:
# Calculate age based on DOB
age = today.year - kid.date_of_birth.year - ((today.month, today.day) < (kid.date_of_birth.month, kid.date_of_birth.day))
kid.age = age
db.session.commit()
@The-Final-Apex
The-Final-Apex / app.py
Created November 24, 2025 10:34
A simple way to backup a sql file (its in instance) the routes are defines outside the code
@app.route('/backup')
def backup():
# Get current timestamp to avoid overwriting
timestamp = datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
backup_folder = os.path.join(BACKUP_DIR, f'backup_{timestamp}')
print(timestamp, backup_folder)
print(BACKUP_DIR)
# Create the backup directory