-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.py
More file actions
159 lines (126 loc) · 4.98 KB
/
Copy pathoptions.py
File metadata and controls
159 lines (126 loc) · 4.98 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Python-Web-API
# v.1.0.0
import os
import json
class options():
#Program Text
PROGRAM_NAME = """
_ _ ___
|_) _|_ |_ _ ._ \ / _ |_ /\ |_) |
| \/ |_ | | (_) | | \/\/ (/_ |_) /--\ | _|_
/
v.1.0.0
Remeber to install device handler on Smartthings:
https://github.com/suxSx/Smartthings-GPIO-Python-Web-API
"""
#Default Values
DETAIL_PRINT_TEXT = "DETAIL_PRINT"
DETAIL_PRINT_VALUE = "1"
HOST_TEXT = "HOST_VALUE"
HOST_VALUE = "0.0.0.0"
PIN_TEXT = "PIN_VALUE"
PIN_VALUE = 17
TIME_TEXT = "TIME_VALUE"
TIME_VALUE = 3
#MSG
error = {
"404": {
"errorCode": "404",
"errorMessage": "Action Not Found, the command you tried does not exist."
},
"notor": {
"errorCode": "666",
"errorMessage": "Well this was unnexpeted, the error message does not exist or is from this world. You are really luck, this is a one in a life time experience!"
}
}
doorMsg = {
"open": {
"doorCode": "1337",
"doorMessage": "Signal for opening sendt"
},
"close": {
"doorCode": "7331",
"doorMessage": "Open signal terminated"
},
"comming": {
"doorCode": "8888",
"doorMessage": "This function is still in development"
},
"running": {
"doorCode": "007",
"doorMessage": "The server are up and running"
}
}
#FOLDER Setup
OP_ROOT_FOLDER_PATH_TEXT = "OP_ROOT_FOLDER_PATH"
OP_ROOT_FOLDER_PATH_VALUE = "\\"
OP_ROOT_FOLDER_NAME_TEXT = "OP_ROOT_FOLDER_NAME"
OP_ROOT_FOLDER_NAME_VALUE = "python-web-api\\"
#Config filename
OP_ROOT_CONFIG = "python-web-api.config"
def root_path(self):
return os.path.abspath(os.sep)
#Global Functions
def printText(self, text, override):
if int(self.DETAIL_PRINT_VALUE) == 1:
print(text)
else:
if override == True:
print(text)
def createRootfolder(self):
self.OP_ROOT_FOLDER_PATH_VALUE = self.root_path()
self.OP_ROOT_FOLDER_PATH_VALUE = self.OP_ROOT_FOLDER_PATH_VALUE + self.OP_ROOT_FOLDER_NAME_VALUE
self.createFolder(self.OP_ROOT_FOLDER_PATH_VALUE)
#Setting up full path starting
self.OP_ROOT_CONFIG = self.OP_ROOT_FOLDER_PATH_VALUE + self.OP_ROOT_CONFIG
self.printText("+ Config file are loacted {}".format(self.OP_ROOT_CONFIG), False)
def createFolder(self, folder):
if not os.path.exists(folder):
os.mkdir(folder)
self.printText("+ Folder created: {}".format(folder), True)
else:
self.printText("+ Folder loacted: {}".format(folder), True)
def saveJSON(self):
self.printText("+ Config export started", False)
DATA = {}
DATA['WEBAPI'] = []
DATA['WEBAPI'].append({
self.DETAIL_PRINT_TEXT : self.DETAIL_PRINT_VALUE,
self.HOST_TEXT : self.HOST_VALUE,
self.PIN_TEXT : self.PIN_VALUE,
self.TIME_TEXT : self.TIME_VALUE
})
if os.path.exists(self.OP_ROOT_CONFIG):
self.printText("+ File: {} exist, deleting it.".format(self.OP_ROOT_CONFIG), False)
os.remove(self.OP_ROOT_CONFIG)
with open(self.OP_ROOT_CONFIG, 'w') as outfile:
json.dump(DATA, outfile)
self.printText("+ Config export end", False)
def setupJSON(self, export):
if export == True:
self.saveJSON()
else:
self.printText("+ Config import started", True)
if os.path.exists(self.OP_ROOT_CONFIG):
with open(self.OP_ROOT_CONFIG) as json_file:
data = json.load(json_file)
for p in data['WEBAPI']:
self.DETAIL_PRINT_VALUE = int(p[self.DETAIL_PRINT_TEXT])
self.HOST_VALUE = p[self.HOST_TEXT]
self.PIN_VALUE = int(p[self.PIN_TEXT])
self.TIME_VALUE = int(p[self.TIME_TEXT])
self.printText("+ {} are set to: {}".format(self.DETAIL_PRINT_TEXT, self.DETAIL_PRINT_VALUE), False)
self.printText("+ {} are set to: {}".format(self.HOST_TEXT, self.HOST_VALUE), False)
self.printText("+ {} are set to: {}".format(self.PIN_TEXT, self.PIN_VALUE), False)
self.printText("+ {} are set to: {}".format(self.TIME_TEXT, self.TIME_VALUE), False)
else:
self.printText("+ Config file dosent exist - using standard", False)
self.saveJSON()
self.printText("+ Config import end", False)
def __init__(self):
#Starting up
print(self.PROGRAM_NAME)
print("+ Text Libray loaded")
#Loading Default Value
self.createRootfolder()
self.setupJSON(False)