-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathedit_config.py
More file actions
202 lines (178 loc) · 4.89 KB
/
edit_config.py
File metadata and controls
202 lines (178 loc) · 4.89 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# try:
# import pip
# except:
# print("PLEASE INSTALL PIP3!!!!!!!!! ---> brew reinstall python3")
# print("PLEASE INSTALL PIP3!!!!!!!!! ---> brew reinstall python3")
# print("PLEASE INSTALL PIP3!!!!!!!!! ---> brew reinstall python3")
# print("PLEASE INSTALL PIP3!!!!!!!!! ---> brew reinstall python3")
# print("PLEASE INSTALL PIP3!!!!!!!!! ---> brew reinstall python3")
# print("PLEASE INSTALL PIP3!!!!!!!!! ---> brew reinstall python3")
# print("PLEASE INSTALL PIP3!!!!!!!!! ---> brew reinstall python3")
# input()
import sys
from threading import *
import time
import math
import os
def ossT(msg):
os.system(msg)
print("############################")
print("############################")
print("############################")
print(msg)
print("############################")
print("############################")
print("############################")
def oss(msg):
t = Thread(target = ossT, args = [msg,])
t.start()
def install(package):
oss("python3 -m pip install "+package)
# pip.main(['install', package])
try:
import pyautogui
except ImportError:
install('pyautogui')
import pyautogui
try:
import pymsgbox
except ImportError:
install('pymsgbox')
import pymsgbox
try:
import yaml
except ImportError:
install('pyyaml')
import yaml
import io
# TV configuration
# tv_config = {
# "tv":
# {"host": "192.168.43.144",
# "protocol": "wss",
# "port": 8002},
# "controller": {
# "name": "RoozRemote"}
# }
path = 'config.yml'
# Write YAML file
# with io.open(path, 'w+', encoding='utf8') as outfile:
# yaml.dump(tv_config, outfile, default_flow_style=False, allow_unicode=True)
# Read YAML file
configuration = None
with open(path, 'r') as stream:
data_loaded = yaml.safe_load(stream)
print("%%%%%%%%%%%%%%%%%%%%%%%%%%")
print(data_loaded)
configuration = data_loaded
try:
if configuration is not None and "tv" in configuration:
tv_ip = configuration["tv"]["host"]
tv_port = configuration["tv"]["port"]
# protocol = configuration["tv"]["protocol"]
except:
print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
print("error loading config", path)
tv_ip = "0.0.0.0"
tv_port = 8002
# protocol = "wss"
a = pymsgbox.prompt(text='Please update your ip! check your tv settings', title='TV IP ADDRESS CONFIG' , default=tv_ip)
# print("!!!!!",a)
p = 8002
tv_ip = a
if a is not None and len(a) > 3 and ":" in a:
tv_ip = a.split(":")[0]
pa = a.split(":")[1]
try:
p = int(pa)
except:
p = 8002
tv_port = p
print("SAVING CONFIG ", tv_ip, tv_port)
configuration["tv"]["host"] = tv_ip
configuration["tv"]["port"] = tv_port
if tv_port is 8002:
configuration["tv"]["protocol"] = "wss"
else:
configuration["tv"]["protocol"] = "ws"
# Write YAML file
with io.open(path, 'w+', encoding='utf8') as outfile:
yaml.dump(configuration, outfile, default_flow_style=False, allow_unicode=True)
with open(path, 'r') as stream:
data_loaded = yaml.safe_load(stream)
# print("%%%%%%%%%%%%%%%%%%%%%%%%%%")
# print(data_loaded)
configuration = data_loaded
print("Loaded Config:")
# print(configuration)
# print()
# def dicts(t):
# try:
# return dict((k, dicts(t[k])) for k in t)
# except TypeError:
# return t
# # from collections import defaultdict
#
# print()
print()
fullLen = len(" ############################################")
print("")
print(" ############################################")
print(" ############################################")
print(" ####### #####")
print(" ####### Configuration Saved #####")
print(" ####### successfully #####")
print(" ####### #####")
for x in configuration:
l = " ####### "+x
s = ""
for a in range((fullLen-5)-len(l)):
s+=" "
s+="#####"
print(l+s)
# print (x)
for y in configuration[x]:
line = " ####### "+y+" "+':'+" "+str(configuration[x][y])
spaces = ""
for a in range((fullLen-5)-len(line)):
spaces+=" "
spaces+="#####"
print (line+spaces)
# print(" ####### "+)
print(" ####### #####")
print(" ############################################")
print(" ############################################")
print("")
# print(defaultdict(configuration))
#
#
# # tree = {'wesley': {'1': {'romulan': {'1': '0', '0': '1'}}, '0': {'romulan': {'1': '0', '0': {'poetry': {'1': {'honor': {'1': '0', '0': '1'}}, '0': {'honor': {'1': '1', '0': '0'}}}}}}}}
#
# def is_number(s):
# return True
# try:
# float(s)
# return True
# except ValueError:
# return False
#
# def go(dic, last_key, current_level):
# for key, value in dic.items():
# if is_number(key):
# for i in range(current_level - 1):
# print("| ", end="")
# print(last_key, "= ", end="")
# print(key, ": ", end="")
# else:
# if current_level > 0:
# print("")
# current_level = current_level + 1
# if isinstance(value, dict):
# go(value, key, current_level)
# else:
# print(value)
#
# go(configuration, None, 0)
#
# print()
# print()