Files

195 lines
4.8 KiB
Python

import db
import logging
import time
import os
import sys
from flags import status
print("loading")
#Logging
logging.basicConfig(
filename='app.log', # Log to a file
level=logging.DEBUG, # Log everything (DEBUG and above)
format='%(asctime)s %(levelname)s %(message)s'
)
logging.info('Application started')
try:
logging.debug('Debug info here')
except Exception as e:
logging.exception('An error occurred')
def insert():
clothe = input("How is the clothe called? ").upper()
weight = float(input("The weight please? "))
pieces = int(input("How many pieces? ints only "))
db.new_part(clothe, weight, pieces)
print("it is inserted")
time.sleep(3)
os.system('cls' if os.name == 'nt' else 'clear')
menu()
def insert():
clothe = input("How is the clothe called? ").upper()
weight = float(input("The weight please? "))
pieces = int(input("How many pieces? ints only "))
db.new_part(clothe, weight, pieces)
print("it is inserted")
time.sleep(3)
os.system('cls' if os.name == 'nt' else 'clear')
menu()
def update():
clothe = input("How is the clothe called? ").upper()
weight = input("The weight please? ")
pieces = input("How many pieces? ints only ")
db.update_weight(clothe, weight)
db.update_pieces(clothe, pieces)
print("it is updated")
time.sleep(3)
os.system('cls' if os.name == 'nt' else 'clear')
menu()
def get_weight():
clothe = input("How is the clothe called? ").upper()
weight = db.fetch_weight(clothe)
print(weight)
time.sleep(3)
os.system('cls' if os.name == 'nt' else 'clear')
menu()
def get_luggage_weight():
weight = db.fetch_luggage_weight()
print(f"The luggage has a weight of {weight}g")
time.sleep(3)
os.system('cls' if os.name == 'nt' else 'clear')
menu()
def get_pieces():
clothe = input("How is the clothe called? ").upper()
pieces = db.fetch_piece(clothe)
print(f"You have {pieces} of {clothe}")
time.sleep(3)
os.system('cls' if os.name == 'nt' else 'clear')
menu()
def get_all_pieces():
pieces = db.fetch_all_pieces()
print(f"You have {pieces} in your luggage")
time.sleep(3)
os.system('cls' if os.name == 'nt' else 'clear')
menu()
def get_clothes():
clothes = db.fetch_clothes()
for clothe in clothes:
print(clothe)
time.sleep(3)
os.system('cls' if os.name == 'nt' else 'clear')
menu()
def get_weight_pieces():
clothe = input("How is the clothe called? ").upper()
weight = db.fetch_weight(clothe)
pieces = db.fetch_piece(clothe)
print(f"You have {pieces} of {clothe}. The weight is {weight}")
time.sleep(3)
os.system('cls' if os.name == 'nt' else 'clear')
menu()
def delete():
clothe = input("How is the clothe called? ").upper()
really = input("Do you really want to delete it? Y/N").upper()
if really == "Y":
db.delete(clothe)
print(f"{clothe} was deleted")
time.sleep(3)
else:
time.sleep(0.5)
logging.info("no item deleted")
os.system('cls' if os.name == 'nt' else 'clear')
menu()
def exit_programm():
time.sleep(0.5)
print(r"""
## ## ##########
### ### ## ##
#### #### ## ##
## #### ## ##########
## ## ## ## ##
## ## ## ##
""")
time.sleep(0.5)
print("")
print("")
print("Disconnect DB")
print("logout")
print("shutting down")
time.sleep(0.75)
os.system('cls' if os.name == 'nt' else 'clear')
sys.exit()
os._exit(1)
def menu():
print("Menu")
print("1: Insert Item")
print("2: Update Item")
print("3: Get weight of clothe")
print("4: Get weight of luggage")
print("5: Get pieces of clothe")
print("6: Get pieces of luggage")
print("7: Get clothes")
print("8: Get weight and pieces of clothes")
print("9: Delete Item")
print("0: EXIT")
choice = input("Type number here ")
os.system('cls' if os.name == 'nt' else 'clear')
logging.info(f"{choice} is choosen")
time.sleep(0.5)
if choice == "1":
insert()
if choice == "2":
update()
if choice == "3":
get_weight()
if choice == "4":
get_luggage_weight()
if choice == "5":
get_pieces()
if choice == "6":
get_all_pieces()
if choice == "7":
get_clothes()
if choice == "8":
get_weight_pieces()
if choice == "0":
exit_programm()
if choice == "9":
delete()
#The Terminal App Starts here
time.sleep(2)
print(r"""
## ## ##########
### ### ## ##
#### #### ## ##
## #### ## ##########
## ## ## ## ##
## ## ## ##
""")
while not status.get_migration():
time.sleep(0.5)
logging.info("Menu is starting")
time.sleep(2.5)
menu()