maringetxway commited on
Commit
36075c9
·
verified ·
1 Parent(s): d23fcf4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -3,11 +3,15 @@ import pandas as pd
3
  import sqlite3
4
  import os
5
  import datetime
 
6
 
7
  DATA_DIR = "data"
8
  os.makedirs(DATA_DIR, exist_ok=True)
9
 
10
  DB_PATH = os.path.join(DATA_DIR, "teamup.db")
 
 
 
11
  ADMIN_CODE = os.getenv("ADMIN_CODE", "")
12
  PAGE_SIZE = 20
13
 
@@ -49,6 +53,15 @@ def init_db():
49
  """)
50
  init_db()
51
 
 
 
 
 
 
 
 
 
 
52
  def submit_profile(name, discord, city, country, address, looking, onlinecheck, languages, laptop, robot, skills, describe3, experience, idea):
53
  if not discord or not city or not country or not laptop or not robot:
54
  return "❌ Please fill in all required fields."
@@ -75,6 +88,7 @@ def submit_profile(name, discord, city, country, address, looking, onlinecheck,
75
  idea=excluded.idea
76
  """, (discord, name, city.title(), country.title(), address, looking, onlinecheck, lang_str.lower(), laptop, robot, skills, describe3, experience, idea))
77
 
 
78
  return "✅ Profile saved!"
79
 
80
  def filter_by_fields(selected_country, selected_city, selected_language, page):
 
3
  import sqlite3
4
  import os
5
  import datetime
6
+ import shutil
7
 
8
  DATA_DIR = "data"
9
  os.makedirs(DATA_DIR, exist_ok=True)
10
 
11
  DB_PATH = os.path.join(DATA_DIR, "teamup.db")
12
+ BACKUP_DIR = os.path.join(DATA_DIR, "backup")
13
+ os.makedirs(BACKUP_DIR, exist_ok=True)
14
+
15
  ADMIN_CODE = os.getenv("ADMIN_CODE", "")
16
  PAGE_SIZE = 20
17
 
 
53
  """)
54
  init_db()
55
 
56
+ def backup_db():
57
+ timestamp = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
58
+ backup_file = os.path.join(BACKUP_DIR, f"teamup_backup_{timestamp}.db")
59
+ shutil.copy(DB_PATH, backup_file)
60
+
61
+ backups = sorted(os.listdir(BACKUP_DIR))
62
+ while len(backups) > 20:
63
+ os.remove(os.path.join(BACKUP_DIR, backups.pop(0)))
64
+
65
  def submit_profile(name, discord, city, country, address, looking, onlinecheck, languages, laptop, robot, skills, describe3, experience, idea):
66
  if not discord or not city or not country or not laptop or not robot:
67
  return "❌ Please fill in all required fields."
 
88
  idea=excluded.idea
89
  """, (discord, name, city.title(), country.title(), address, looking, onlinecheck, lang_str.lower(), laptop, robot, skills, describe3, experience, idea))
90
 
91
+ backup_db()
92
  return "✅ Profile saved!"
93
 
94
  def filter_by_fields(selected_country, selected_city, selected_language, page):