Skip to content
Permalink
51ff405960
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
78 lines (69 sloc) 2.79 KB
import sqlite3 as sql
from datetime import datetime
"""Validation for fields"""
database_user = "app/databases/users.db" # Taking the databases
database_locations = 'app/databases/locations.db'
def create():
with sql.connect(database_user) as cur:
try: # Tries the sql table
cur.execute("CREATE TABLE UserDatabase(username VARCHAR2(20), password VARCHAR2(20), realname VARCHAR2(20), dob VARCHAR2(20), weight VARCHAR2(20));")
except:
pass
def user_exists(username): # Checks for username
with sql.connect(database_user) as cur:
com = f"SELECT count(*) FROM UserDatabase WHERE username='{username}';"
print(com)
res = cur.execute(com).fetchone()[0]
if res == 0:
return False
else:
return True
def tid_exists(username): # Checks for tid
with sql.connect(database_locations) as cur:
com = f"SELECT count(*) FROM Location WHERE tid='{username}';"
print(com)
res = cur.execute(com).fetchone()[0]
if res == 0:
return False
else:
return True
def compare(username, value_in, value_type): # Comparing
with sql.connect(database_user) as cur:
com = f"SELECT {value_type} FROM UserDatabase WHERE username='{username}';"
print(com)
res = cur.execute(com).fetchone()[0]
print(f"comparing - {value_in} == {res}")
if value_in == res:
return True
else:
return False
def check_month(month, day): # Checks the month and day
if month in [1, 3, 5, 7, 8, 10, 12]:
if (day > 0 and day <= 31):
return True
else:
return False
elif month == 2:
if (day > 0 and day <= 28): # Checking February
return True
else:
return False
else:
if (day > 0 and day <= 30):
return True
else:
return False
def check_date(day, month, year): # Checks full date
today = datetime.today().strftime('%Y-%m-%d').split("-")
if int(year) > int(today[0]):
return False
elif int(year) == int(today[0]):
if int(month) > int(today[1]):
return False
else:
if int(day) > int(today[2]):
return False
else:
return check_month(int(month), int(day))
else:
return check_month(int(month), int(day))