Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
220a06208a | ||
|
|
d268cb01d5 |
@@ -95,6 +95,7 @@ def fetch_all_pieces():
|
|||||||
result = session.query(Items.pieces).all()
|
result = session.query(Items.pieces).all()
|
||||||
return [row[0] for row in session.query(Items.pieces).all()]
|
return [row[0] for row in session.query(Items.pieces).all()]
|
||||||
|
|
||||||
|
#Checks if clothe is in db
|
||||||
def check_clothe(clothe_type):
|
def check_clothe(clothe_type):
|
||||||
exists = session.query(Items.clothes).filter_by(clothes=clothe_type).first() is not None
|
exists = session.query(Items.clothes).filter_by(clothes=clothe_type).first() is not None
|
||||||
return exists
|
return exists
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
from dotenv import load_dotenv
|
from migration.alembic_scipt import auto_lookup
|
||||||
import db
|
import time
|
||||||
import os
|
|
||||||
import logging
|
import logging
|
||||||
import auth.api_security as auth
|
import auth.api_security as auth
|
||||||
|
import os
|
||||||
|
|
||||||
#Logging
|
#Logging
|
||||||
|
|
||||||
@@ -18,41 +18,19 @@ try:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception('An error occurred')
|
logging.exception('An error occurred')
|
||||||
|
|
||||||
load_dotenv()
|
|
||||||
db_name = os.getenv("DB_NAME")
|
def new_table():
|
||||||
db_psswd = os.getenv("DB_PASSWORD")
|
auto_lookup()
|
||||||
db_user = os.getenv("DB_USER")
|
|
||||||
db_port = os.getenv("DB_PORT") or "3306"
|
def admin():
|
||||||
db_host = os.getenv("DB_HOST")
|
token = auth.admin_token()
|
||||||
if db_host == None:
|
print(token)
|
||||||
logging.error("no hostname provided")
|
logging.info(token)
|
||||||
|
time.sleep(300)
|
||||||
|
os.remove("app.log")
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
|
||||||
db.connect(db_user, db_psswd, db_host, int(db_port), db_name)
|
|
||||||
|
|
||||||
def new_table(name):
|
new_table()
|
||||||
cursor = db.connection.cursor()
|
admin()
|
||||||
if name == "tokens":
|
|
||||||
executed = "CREATE TABLE tokens (tokens VARCHAR(255) PRIMARY KEY, `time` VARCHAR(255), end_date VARCHAR(255))"
|
|
||||||
cursor.execute(executed)
|
|
||||||
db.connection.commit()
|
|
||||||
logging.info("Table 'tokens' created")
|
|
||||||
|
|
||||||
if name == "luggage":
|
|
||||||
executed = "CREATE TABLE luggage (clothes VARCHAR(50) PRIMARY KEY, weight DECIMAL(20,2), pieces INT(11))"
|
|
||||||
cursor.execute(executed)
|
|
||||||
db.connection.commit()
|
|
||||||
logging.info("Table 'luggage' created")
|
|
||||||
|
|
||||||
if name == "user":
|
|
||||||
executed = "CREATE TABLE user (username VARCHAR(50) PRIMARY KEY, password VARCHAR(255))"
|
|
||||||
cursor.execute(executed)
|
|
||||||
db.connection.commit()
|
|
||||||
logging.info("Table 'user' created")
|
|
||||||
|
|
||||||
|
|
||||||
new_table("tokens")
|
|
||||||
new_table("luggage")
|
|
||||||
new_table("user")
|
|
||||||
print(auth.admin_token())
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user