-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
96 lines (81 loc) · 3.3 KB
/
Copy pathhelpers.py
File metadata and controls
96 lines (81 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import aclist
layout = aclist.LAYOUT
import sqlite3
from os import system
#creates new SQL table for AC
def createAC():
Name = input("Aircraft Make/Model: ")
Reg = input("What is the airctaft registration? ")
ArmFront = input("What is the front Arm? ")
ArmPax = input("What is the passenger's Arm? ")
ArmFuel = input("What is the fuel Arm? ")
def update():
# connect to the aircraft-ledgers database
conn = sqlite3.connect("./databases/aircraft-ledger.db")
cur = conn.cursor()
# iterate over the list of manufacturers
for manufacturer in aclist.ACMAKE:
# open the database for the current manufacturer
manufacturer_db = sqlite3.connect(f"./databases/{manufacturer.lower()}.db")
manufacturer_cur = manufacturer_db.cursor()
# get the list of tables in the manufacturer database
manufacturer_cur.execute("SELECT name FROM sqlite_schema WHERE type ='table' AND name NOT LIKE 'sqlite_%';")
tables = [table[0] for table in manufacturer_cur.fetchall()]
# iterate over the list of tables
for table in tables:
# checks if the table name is already present in the aircraft-ledgers database
cur.execute(f"SELECT type FROM {manufacturer.lower()} WHERE type=?", (table,))
if not cur.fetchone():
# Insert the table name into the aircraft-ledgers database
cur.execute(f"INSERT INTO {manufacturer.lower()} (type) VALUES (?)", (table,))
# Close the manufacturer database
manufacturer_db.close()
# Commit the transaction
conn.commit()
# Close the aircraft-ledgers database
conn.close()
sqllist = {
"tables":"SELECT name FROM sqlite_schema WHERE type ='table' AND name NOT LIKE 'sqlite_%';",
"listcessna":"SELECT type FROM cessna;",
"listpiper":"SELECT type FROM piper;",
"listdiamond":"SELECT type FROM diamond;",
"listall":"SELECT * FROM {};",
"createAC":"CREATE TABLE {}(ac_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, registration TEXT NOT NULL UNIQUE, bew INTEGER NOT NULL, maxweight INTEGER NOT NULL, cg INTEGER NOT NULL, moment INTEGER NOT NULL, year INTEGER NOT NULL);"
}
def connection(database):
try:
conn = sqlite3.connect(f"./databases/{database}.db")
cur = conn.cursor()
return cur
except:
print(f"Could not connect to {database} database.")
def statement(db, state):
conn = sqlite3.connect(f"./databases/{db}.db")
cur = conn.cursor()
sqlstate = (sqllist[state])
query = cur.execute(sqlstate)
return query
def selector(listerino):
while True:
try:
print("\n",listerino,"\n")
selection = input("Type choice from one from the above: ")
selection.lower()
if selection in listerino:
system('clear')
#print("Success")
return selection
else:
system('clear')
print("\nInvalid option.\n")
choice = "y"
if input("Would you like to create a new one? y/n\n") == choice:
system('clear')
return selection.lower()
except Exception as x:
print(x)
break
def clean(string):
string.strip()
string.upper()
return string