-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interface_Function.py
136 lines (106 loc) · 4.05 KB
/
Interface_Function.py
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import datetime
import time
import sqlite3
def Valid_Input(DATER,TIMER,latitude,longtitude,Number_of_satellites_being_tracked,altitude,SPEED):
if DATER!="" and DATER!="YYYY-MM-DD":
try:
datetime.datetime.strptime(DATER, '%Y-%m-%d')
except ValueError:
raise ValueError("Incorrect Date format, should be YYYY-MM-DD")
if TIMER!="" and TIMER!="HH:MM:SS":
try:
time.strptime(TIMER, '%H:%M:%S')
except ValueError:
raise ValueError("Incorrect TIME format, should be HH:SS:MM")
if latitude!="":
try:
latitude = float(latitude)
if latitude==0:
raise ValueError('latitude cannot be length empty ')
except Exception as error:
raise ValueError(repr(error))
if longtitude!="":
try:
longtitude = float(longtitude)
if longtitude==0:
raise ValueError('longtitude cannot be length empty')
except Exception as error:
raise ValueError(repr(error))
if Number_of_satellites_being_tracked!="":
try:
Number_of_satellites_being_tracked = int(Number_of_satellites_being_tracked)
if Number_of_satellites_being_tracked<=0:
raise ValueError('Number_of_satellites_being_tracked cannot be length empty or negative')
except Exception as error:
raise ValueError(repr(error))
if altitude!="":
try:
altitude = float(altitude)
if altitude==0:
raise ValueError('altitude cannot be length empty')
except Exception as error:
raise ValueError(repr(error))
if SPEED!="":
try:
SPEED = int(SPEED)
if SPEED<0:
raise ValueError('SPEED cannot be negative')
except Exception as error:
raise ValueError(repr(error))
def create_Query(DATER,TIMER,latitude,longtitude,Number_of_satellites_being_tracked,altitude,SPEED):
Query=""
count = 0
if DATER!="" and DATER!="YYYY-MM-DD":
Query = "where dater="+"'"+DATER+"'"
count=count+1
if TIMER!="" and TIMER!="HH:MM:SS":
if count==0:
Query = "where timer="+"'"+TIMER+"'"
else:
Query= Query + " And timer="+"'"+TIMER+"'"
count=count+1
if latitude!="":
latitude = int(latitude)
if count==0:
Query = "where CAST(latitude AS INT)="+""+str(latitude)+""
else:
Query= Query + " And CAST(latitude AS INT)="+""+str(latitude)+""
count=count+1
if longtitude!="":
longtitude = int(longtitude)
if count==0:
Query = "where CAST(longtitude AS INT)="+""+str(longtitude)+""
else:
Query= Query + " And CAST(longtitude AS INT)="+""+str(longtitude)+""
count=count+1
if Number_of_satellites_being_tracked!="":
Number_of_satellites_being_tracked = int(Number_of_satellites_being_tracked)
if count==0:
Query = "where CAST(Number_of_satellites_being_tracked AS INT)="+""+str(Number_of_satellites_being_tracked)+""
else:
Query= Query + " And CAST(Number_of_satellites_being_tracked AS INT)="+""+str(Number_of_satellites_being_tracked)+""
count=count+1
if altitude!="":
altitude = int(altitude)
if count==0:
Query = "where CAST(altitude AS INT)="+""+str(altitude)+""
else:
Query=Query + " And CAST(altitude AS INT)="+""+str(altitude)+""
count=count+1
if SPEED!="":
SPEED = int(SPEED)
if count==0:
Query = "where CAST(SPEED AS INT)="+""+str(SPEED)+""
else:
Query=Query + " And CAST(SPEED AS INT)="+""+str(SPEED)+""
count=count+1
return Query
def Count_Files_In_Db():
conn = sqlite3.connect("tk.db")
counter=0
cursor = conn.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
for tbl in tables:
counter= counter +1
return counter