-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocationCLI.py
More file actions
116 lines (97 loc) · 2.97 KB
/
Copy pathLocationCLI.py
File metadata and controls
116 lines (97 loc) · 2.97 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import sqlite3
def AddLocation():
LocationName=input("Please enter the name of the location: ")
while 1:
try:
Latitude=float(input("Please enter the latitude of the location: "))
break
except:
print("Not a valid latitude!")
while 1:
try:
Longitude=float(input("Please enter the longitude of the location: "))
break
except:
print("Not a valid longitude!")
Link=input("Please enter the link for the location: ")
with sqlite3.connect("Database.db") as db:
cursor=db.cursor()
sql="select LocationID from Location"
cursor.execute(sql)
total=cursor.fetchall()
LocationID=1
for each in total:
LocationID+=1
Location=[LocationID,LocationName,Latitude,Longitude,Link]
Valid=ValidateLocation(Location)
if Valid:
AddLocationToDatabase(Location)
print()
print("Added Successfully!")
def ValidateLocation(Loc):
if 3<len(Loc[0])<30:
if -90<=Loc[1]<=90:
if -180<=Loc[2]<=180:
if 4<=len(Loc[3])<=75:
return True
print("Failed - Values did not meet specifications!")
return False
def AddLocationToDatabase(values):
with sqlite3.connect("Database.db") as db:
cursor=db.cursor()
sql="""insert into Location (
LocationID,
LocationName,
Latitude,
Longitude,
Link
)
values (?,?,?,?,?)
"""
cursor.execute(sql,values)
db.commit()
def EditLocation():
ViewLocation()
def DeleteLocation():
pass
def ViewLocation():
with sqlite3.connect("database.db") as db:
cursor=db.cursor()
sql="select * from Location"
cursor.execute(sql)
Users=cursor.fetchall()
for each in Users:
print("Location {0} - ".format(each[0]))
print("Name - {0}".format(each[1]))
print("Longitude - {0}".format(each[2]))
print("Latitude - {0}".format(each[3]))
print("Link - {0}".format(each[4]))
def DisplayMainMenu():
print()
print("{0}Welcome to Location CLI{0}".format(("="*10)))
print("What do you wish to do?")
print("1. Add New Location")
print("2. Edit Existing Location")
print("3. Delete Existing Location")
print("4. View All Existing Locations")
print("9. Quit CLI")
print()
def main():
while 1:
DisplayMainMenu()
choice=input(": ")
if choice=="1":
AddLocation()
elif choice=="2":
EditLocation()
elif choice=="3":
DeleteLocation()
elif choice=="4":
ViewLocation()
elif choice=="9":
print("Goodbye")
return
else:
print("That's not a valid input (1-9)")
if __name__=="__main__":
main()