-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
205 lines (178 loc) · 5.09 KB
/
main.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
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
203
204
205
#!/Library/Frameworks/Python.framework/Versions/3.8/bin/python3
import codec
print('Codec.py imported...')
import sys
#import parser
from configparser import ConfigParser
config = ConfigParser()
#set config file
config.read('config.ini')
#set variables from config file
speed = config.get('SETTINGS', 'speed')
key = config.get('SETTINGS', 'key')
x = codec.decode(key)
#if not codec.decode(key) == '6942':
# sys.exit()
#setup random timer to make loadings look cool
from random import randint
loadings = True
z = 1
def load_time():
global z
global loadings
if speed == 0:
loadings = False
if speed == 1:
z = 2
elif speed == 2:
z = 5
elif speed == 3:
z = 8
x = randint(1, z)
if loadings == False:
return(0)
if loadings == True:
return(x/10)
#import libraries
import time
print('Time module imported...')
time.sleep(load_time())
import sys
print('SYS module imported...')
time.sleep(load_time())
import pickle
print("Pickle module imported...")
time.sleep(load_time())
import os
print("OS module imported...")
time.sleep(load_time())
#load data from data.dat
try:
data = pickle.load(open("data.dat", "rb"))
print('Data successfullying imported...')
time.sleep(load_time())
except FileNotFoundError:
print("Data.dat file not found or corrupted, please run 'python3 clean.py' to create new file.")
sys.exit()
local = data[0]
tasks = data[1]
users = data[2]
time.sleep(load_time())
print('Launched.')
print(" _____ _____ __ _ _ \n | __ \\ | __ \\ / _(_) | \n | | | | ___ ___| |__) | __ ___ | |_ _| | ___ _ __ \n | | | |/ _ \\/ __| ___/ '__/ _ \\| _| | |/ _ \\ '__|\n | |__| | (_) \\__ \\ | | | | (_) | | | | | __/ | \n |_____/ \\___/|___/_| |_| \\___/|_| |_|_|\\___|_|\n")
#create save function to save the current local, tasks, users variables into data.dat
def save():
save_data = [local, tasks, users]
pickle.dump(save_data, open("data.dat", "wb"))
print(f"File saved to: " + os.path.abspath("data.dat"))
close = False
while close == False:
task = input(': ').split()
tasked = False
if task[0] == 'help':
print('')
for item in tasks:
print(f"{codec.decode(item)} -- {codec.decode(tasks[item])}")
print('')
tasked = True
if task[0] == 'close':
save()
sys.exit('Closed with task-exit.')
if task[0] == 'save':
save()
tasked = True
if task[0] == 'ls' and len(task) == 1:
print('\nLOCAL:\n {')
for item in local:
print(f" '{item}': {local[item]}")
print('}')
print('\nTASKS:\n {')
for item in tasks:
print(f" '{codec.decode(item)}': '{codec.decode(tasks[item])}'")
print('}')
print('\nUSERS:\n\n {')
for item in users:
_usrdict = users[item]
print(f"{codec.decode(item)}")
for info in _usrdict:
print(f" '{codec.decode(info)}': {codec.decode(_usrdict[info])}")
print('}\n')
tasked = True
elif task[0] == 'ls' and len(task) > 1:
continue_ = True
try:
temp_dict = eval(task[1])
except NameError:
print('\nNameError, please enter a valid dictionary;')
continue_ = False
while tasked == False and continue_ == True:
print(f'\n{task[1]}:\n {{')
for item in temp_dict:
print(f" '{item}': {temp_dict[item]}")
print('}\n')
tasked = True
if task[0] == 'clear':
os.system('clear')
tasked = True
if task[0] == 'useradd':
__continue__ = True
_user = codec.encode(task[1])
if __continue__ == True:
if len(task) > 1:
new_username = _user
users[new_username] = {}
tasked = True
elif len(task) < 2:
print("'useradd' requires 1 argument, 0 given")
tasked = True
if task[0] == 'userdel':
__continue__ = True
_user = codec.encode(task[1])
if _user not in users:
print('Please enter a valid user or create a new profile.')
__continue__ = False
tasked = True
if __continue__ == True:
if len(task) > 1:
user = task[1]
del users[_user]
tasked = True
elif len(task) < 2:
print("'userdel' requires 1 argument, 0 given")
tasked = True
if task[0] == 'addinfo' and len(task) == 4:
__continue__ = True
_user = codec.encode(task[1])
_item = codec.encode(task[2])
_info = codec.encode(task[3])
if _user not in users:
print('Please enter a valid user or create a new profile.')
__continue__ = False
if __continue__ == True:
user_dict = users[_user]
user_dict[_item] = _info
save()
tasked = True
if task[0] == 'rminfo' and len(task) == 3:
__continue__ = True
_user = codec.encode(task[1])
_item = codec.encode(task[2])
if _user not in users:
print('Please enter a valid user or create a new profile.')
__continue__ = False
tasked = True
if __continue__ == True:
print('Deleting...')
user_dict = users[_user]
user_dict.pop(_item, None)
print('Done.')
tasked = True
if task[0] == 'encode' and len(task) > 1:
print(codec.encode(task[1]))
tasked = True
if task[0] == 'decode' and len(task) > 1:
print(codec.decode(task[1]))
tasked = True
#if a valid command wasn't ran, tasked will stay == False, causing this to run:
if tasked == False:
print("Please enter a valid command, try 'help' for a list of commands.")