Skip to content

Instantly share code, notes, and snippets.

@LovingMelody
Last active September 18, 2017 19:12
Show Gist options
  • Save LovingMelody/343cd8d5106134f57fea94cd31645e55 to your computer and use it in GitHub Desktop.
Save LovingMelody/343cd8d5106134f57fea94cd31645e55 to your computer and use it in GitHub Desktop.
wynaut
#!/usr/bin/python3
import\
sys
import\
os
import\
time
import\
math
import\
psutil
from\
subprocess\
import\
PIPE
import\
subprocess
import\
traceback
import\
sys
import\
zipfile
from\
urllib.request\
import\
urlretrieve
from\
shutil\
import\
rmtree
core\
=\
psutil\
.Process\
(
)
home\
=\
os\
.\
path\
.\
expanduser\
(
"\
~\
"
)
options\
=\
{
'\
d\
e\
b\
u\
g\
'\
:\
False,
'\
F\
i\
r\
s\
t\
\
S\
t\
a\
r\
t\
':\
False,
'\
e\
d\
i\
t\
\
c\
o\
n\
f\
i\
g\
'\
:\
False
}
list_of_commands\
=\
[
'\
E\
d\
i\
t\
\
C\
o\
n\
f\
i\
g\
'\
,
'\
T\
e\
s\
t\
\
P\
y\
t\
h\
o\
n\
'\
,
'\
U\
p\
d\
a\
t\
e\
\
P\
I\
P\
\
D\
e\
p\
e\
n\
d\
e\
n\
c\
i\
e\
s\
'\
,
'\
s\
p\
e\
e\
d\
t\
e\
s\
t\
'\
,
'\
s\
t\
a\
r\
t\
\
b\
o\
t\
'\
,
'\
k\
i\
l\
l\
\
p\
i\
d\
'\
,
'\
b\
a\
s\
h\
'\
,
'\
u\
p\
d\
a\
t\
e\
'\
,
'\
t\
a\
s\
k\
\
m\
a\
n\
a\
g\
e\
r\
'
]
list_of_commands\
+=\
[
'\
E\
x\
i\
t\
'
]
running_pid\
=\
{
'list':\
[]
}
val\
=\
{
}
def \
yes_or_no\
(
question\
=\
None\
)\
:
while True\
:
try\
:
if\
question:
prompt\
=\
question\
+\
'\
Y\
e\
s\
\
o\
r\
\
N\
o\
\n\
>\
>\
>\
\
'
else\
:
prompt\
=\
'\
Y\
e\
s\
\
o\
r\
\
N\
o\
\n\
>\
>\
>\
\
'
x\
=\
input\
(
prompt
)\
.\
lower\
(
)
if\
x\
in\
[
'yes',
'ye',
'y',
'no',
'n'
]\
:
if\
x\
.\
startswith\
(
'\
y\
'
):
return\
True
if\
x\
.\
startswith\
(
'\
n\
'
)\
:
return\
False
except\
Exception:
pass
def\
get_values\
(
fresh\
=\
False\
)\
:
path_to_config\
=\
'{0}/Flora_Command-Line/'\
.\
format\
(home)
if\
not\
os\
.\
path\
.\
exists\
(
path_to_config
)\
:
os\
.\
mkdir\
(
path_to_config
)
f\
=\
open\
(
'\
{\
0\
}\
/\
v\
a\
l\
u\
e\
s\
.\
t\
x\
t\
'\
.\
format\
(
path_to_config
)\
,
'\
w\
'
)
f\
.\
close\
(
)
fresh\
=\
True
if\
fresh\
:
val\
[
'\
n\
a\
m\
e\
'
]\
=\
str\
(
input\
(
'\
W\
h\
a\
t\
\
S\
h\
o\
u\
l\
d\
\
I\
\
c\
a\
l\
l\
\
y\
o\
u\
?\
\n\
N\
a\
m\
e\
:\
\
'
)
)\
.\
strip\
(
)
text\
=\
'\
{\
0\
}\
\n\
'\
.\
format\
(
val\
[
'\
n\
a\
m\
e\
'
]
)
prompt\
=\
'\
D\
o\
\
Y\
o\
u\
\
H\
a\
v\
e\
\
a\
n\
y\
\
l\
i\
b\
r\
a\
r\
i\
e\
s\
\
t\
h\
a\
t\
\
c\
a\
n\
n\
o\
t\
\
b\
e\
\
u\
p\
d\
a\
t\
e\
d\
\
t\
h\
r\
o\
u\
g\
h\
\
p\
i\
p\
\
-\
U\
\
{\
n\
a\
m\
e\
}\
\
[\
l\
i\
k\
e\
\
a\
\
g\
i\
t\
\
r\
e\
p\
o\
]\
\n\
Y\
e\
s\
/\
N\
o\
:\
\
'
if\
yes_or_no\
(
prompt
)\
:
pip_list\
=\
[
True
]
adding_entries\
=\
True
print\
(
'\
P\
l\
e\
a\
s\
e\
\
P\
r\
e\
s\
s\
\
E\
n\
t\
e\
r\
\
A\
f\
t\
e\
r\
\
e\
a\
c\
h\
\
c\
o\
m\
m\
a\
n\
d\
.\
\n\
T\
y\
p\
e\
\
"\
D\
o\
n\
e\
"\
\
w\
h\
e\
n\
\
d\
o\
n\
e\
.\
'
)
while\
adding_entries\
:
entry\
=\
str\
(
input\
(
'\
C\
o\
m\
m\
a\
n\
d\
:\
\
'
)
)\
.\
strip\
(
)
if\
entry\
.\
lower\
(
)\
!=\
'\
d\
o\
n\
e\
'\
:
pip_list\
+=\
[entry]
else\
:
adding_entries\
=\
False
if\
len\
(
pip_list
)\
==\
1\
:
pip_list\
=\
[
False
]
else\
:
pip_list\
=\
[
False
]
val\
[
'pip list'
]\
=\
pip_list
text\
+=\
'{0}\n'\
.\
format\
(
val\
[
'pip list'
]
)
f\
=\
open\
(\
'{0}/values.txt'\
.\
format\
(
path_to_config
)\
,
'w'
)
f\
.\
write\
(
text
)
f\
.\
close\
()
else\
:
with\
open\
(
'{0}/values.txt'\
.\
format\
(path_to_config)\
,\
'r'
)\
as\
f\
:
lines\
=\
f\
.\
readlines\
(
)
for\
line\
in \
lines:
if \
line\
.\
startswith\
(
'['
) \
and \
line\
.\
endswith\
(
']'
)\
:
line\
.\
strip\
(
'['
)\
.\
strip\
(
']'
)
line\
.\
split\
(
'\
\'\
,\
\
\'\
'
)
for\
entry \
in \
line\
:
line\
[
line\
.\
index\
(
entry
)
]\
=\
entry\
.\
strip\
(
'\
\'\
'
)\
.\
strip\
(
)
val\
[\
'\
p\
i\
p\
\
l\
i\
s\
t\
'
]\
=\
line
elif \
lines\
.\
index\
(
line
)\
==\
0\
:
val\
[
'\
n\
a\
m\
e\
']\
=\
line\
.\
strip\
(
)
def \
command_handler\
(
command
)\
:
if \
command\
:
if \
command \
!= \
'\
E\
x\
i\
t\
'\
:
try\
:
command_dictionary\
[command]\
(
)
except\
:
print\
(
'\
C\
o\
m\
m\
a\
n\
d\
\
F\
a\
i\
l\
e\
d\
'
)
input\
(
'\
p\
r\
e\
s\
s\
\
E\
n\
t\
e\
r\
\
t\
o\
\
c\
o\
n\
t\
i\
n\
u\
e\
'
)
if \
len\
(
running_pid\
[
'\
l\
i\
s\
t\
'
]
)\
>\
0\
:
print\
(
'\
r\
u\
n\
n\
i\
n\
g\
\
P\
I\
D\
:\
'\
,
running_pid\
[
'\
l\
i\
s\
t\
'
]
)
main\
(
)
else\
:
exiter\
(
)
else\
:
main\
(
)
def \
edit_config\
(
)\
:
pass # "Add something here
def \
bot_starter\
(
)\
:
process\
=\
None
path_to_bot\
=\
'\
{\
0\
}\
/\
F\
l\
o\
r\
a\
_\
C\
o\
m\
m\
a\
n\
d\
-\
L\
i\
n\
e\
/\
'\
.\
format\
(
home
)
print\
(
path_to_bot
)
print\
(
os\
.\
listdir\
(
path_to_bot
)
)
try\
:
with \
open\
(
'\
{\
0\
}\
b\
o\
t\
.\
t\
x\
t\
'\
.\
format\
(
path_to_bot
)\
,
'\
r\
'
) \
as \
f\
:
x\
=\
f\
.\
readlines\
(
)
name,\
bot_command\
=\
x
f\
.\
close\
(
)
print\
(
'\
W\
o\
u\
l\
d\
\
y\
o\
u\
\
l\
i\
k\
e\
\
t\
o\
\
s\
t\
a\
r\
t\
'\
,
name,
'\
w\
i\
t\
h\
\
t\
h\
e\
\
c\
o\
m\
m\
a\
n\
d\
:\
\n\
',\
bot_command
)
if \
not \
yes_or_no\
(
)\
:
if\
not\
yes_or_no\
('\
W\
o\
u\
l\
d\
\
y\
o\
u\
\
l\
i\
k\
e\
\
t\
o\
\
s\
t\
a\
r\
t\
\
t\
h\
e\
\
b\
o\
t\
\
a\
t\
\
a\
l\
l\
?\
'
)\
:
return
while \
True\
:
name\
=\
input\
(
'\
B\
o\
t\
s\
\
N\
a\
m\
e\
\n\
>\
>\
>\
\
'
)
bot_command\
=\
input\
(
'\
B\
o\
t\
\
S\
t\
a\
r\
t\
\
C\
o\
m\
m\
a\
n\
d\
\n\
>\
>\
>\
\
'
)
if \
yes_or_no\
(
'\
W\
o\
u\
l\
d\
\
y\
o\
u\
\
l\
i\
k\
e\
\
t\
o\
\
s\
t\
a\
r\
t\
\
{\
}\
\
w\
i\
t\
h\
\
t\
h\
e\
\
c\
o\
m\
m\
a\
n\
d\
:\
\n\
{\
1\
}\
'.\
format\
(
name\
,\
bot_command
)
)\
:
f\
=\
open\
(
'\
{\
0\
}\
/\
b\
o\
t\
.\
t\
x\
t\
'\
.\
format\
(
path_to_bot
)\
,\
'\
w\
'
)
text\
=\
'\
{\
0\
}\
\n\
{\
1\
}\
'.\
format\
(
name\
,
bot_command
)
f\
.\
write\
(
text
)
f\
.\
close\
(
)
break
print\
(
'\
S\
t\
a\
r\
t\
i\
n\
g\
\
B\
o\
t\
.\
.\
.\
'
)
try\
:
process\
=\
psutil\
.\
Popen\
(
bot_command\
.\
split\
(
),\
stdout\
=\
PIPE
)
except \
Exception \
as \
e\
:
traceback\
.\
format_exception\
(
)
except\
:
try\
:
print\
(
os\
.\
listdir\
(
path_to_bot
)
)
f\
=\
open\
(
'\
{\
0\
}\
b\
o\
t\
.\
t\
x\
t\
'\
.\
format\
(
path_to_bot
)\
,\
'\
w\
'
)
name\
=\
input\
(
'\
B\
o\
t\
s\
\
N\
a\
m\
e\
:\
\
')
print\
(
'\
P\
l\
e\
a\
s\
e\
\
i\
n\
p\
u\
t\
\
c\
o\
m\
m\
a\
n\
d\
\
n\
e\
e\
d\
e\
d\
\
t\
o\
\
s\
t\
a\
r\
t\
\
b\
o\
t\
\
f\
r\
o\
m\
\
r\
o\
o\
t\
\
d\
i\
r\
e\
c\
t\
o\
r\
y\
'
)
command_need\
=\
input\
(
'\
C\
o\
m\
m\
a\
n\
d\
:\
\
'
)
text\
=\
'\
{\
0\
}\
\n\
{\
1\
}\
'\
.\
format\
(
name\
,
command_need
)
f\
.\
write\
(
text
)
f\
.\
close\
(
)
print\
(
'\
S\
t\
a\
r\
t\
i\
n\
g\
\
B\
o\
t\
'
)
process\
=\
psutil\
.\
Popen\
(
command_need\
.\
split\
(
)\
,
stdout\
=\
PIPE
)
# process = psutil.Popen(['python3.5', '/home/fuzen/Flora/flora.py'], stdout=PIPE)
except\
Exception \
as \
e\
:
print\
(
e
)
if \
process\
:
print\
(
'\
B\
o\
t\
\
S\
t\
a\
r\
t\
e\
d\
\
o\
n\
\
I\
D\
:\
'\
,
process\
.\
pid
)
running_pid\
[
'\
l\
i\
s\
t\
'
]\
+=\
[
process
]
else\
:
print\
(
'\
C\
o\
u\
l\
d\
\
n\
o\
t\
\
s\
t\
a\
r\
t\
\
b\
o\
t\
'
)
def \
on_terminate\
(
proc
)\
:
print\
(
"\
p\
r\
o\
c\
e\
s\
s\
\
{\
}\
\
t\
e\
r\
m\
i\
n\
a\
t\
e\
d\
\
w\
i\
t\
h\
\
e\
x\
i\
t\
\
c\
o\
d\
e\
\
{\
}\
"\
.\
format\
(
proc\
,
proc\
.\
returncode
)
)
def \
process_killer\
(
)\
:
for \
p \
in \
running_pid\
[
'\
l\
i\
s\
t\
'
]\
:
p\
.\
terminate\
(
)
try\
:
p\
.\
kill\
(
)
except\
:
print\
(
'\
f\
a\
i\
l\
e\
d\
\
t\
o\
\
k\
i\
l\
l\
\
{\
0\
}\
'\
.\
format\
(
p
)
)
def \
speed_test\
(
)\
:
share\
=\
None
print\
(
'\
R\
u\
n\
n\
i\
n\
g\
\
S\
p\
e\
e\
d\
t\
e\
s\
t\
'
)
a\
=\
os\
.\
popen\
(
'\
s\
p\
e\
e\
d\
t\
e\
s\
t\
-\
c\
l\
i\
\
-\
-\
s\
h\
a\
r\
e\
'
)\
.\
readlines\
(
)
try\
:
a\
,\
share\
=\
speed_test_formatter\
(
a
)
except \
Exception \
as \
e\
:
print\
(
e
)
print\
(
'\
r\
e\
q\
u\
i\
r\
e\
d\
\
d\
e\
p\
e\
n\
d\
e\
n\
c\
y\
\
n\
o\
t\
\
i\
n\
s\
t\
a\
l\
l\
e\
d\
'
)
if \
yes_or_no\
(
'\
W\
o\
u\
l\
d\
\
y\
o\
u\
\
l\
i\
k\
e\
\
f\
o\
r\
\
m\
e\
\
t\
o\
\
i\
n\
s\
t\
a\
l\
l\
\
s\
p\
e\
e\
d\
t\
e\
s\
t\
-\
c\
l\
i\
?\
'
)\
:
if \
os\
.\
name\
!=\
'\
n\
t\
'\
:
a\
=\
os\
.\
popen\
(
'\
s\
u\
d\
o\
\
p\
i\
p\
\
i\
n\
s\
t\
a\
l\
l\
\
s\
p\
e\
e\
d\
t\
e\
s\
t\
-\
c\
l\
i\
\
-\
U\
')
else\
:
a\
=\
os\
.\
popen\
(
'\
p\
i\
p\
\
i\
n\
s\
t\
a\
l\
l\
\
s\
p\
e\
e\
d\
t\
e\
s\
t\
-\
c\
l\
i\
\
-\
U\
'
)
a\
=\
os\
.\
popen\
(
'\
s\
p\
e\
e\
d\
t\
e\
s\
t\
-\
c\
l\
i\
\
-\
-\
s\
h\
a\
r\
e\
'
)
cheker\
=\
'\
'\
.\
join\
(
a
)
print\
(
cheker
)
cheker\
=\
len\
(
cheker\
.\
split\
(
'\
s\
p\
e\
e\
d\
t\
e\
s\
t\
-\
c\
l\
i\
'
)
)\
==\
2
if \
cheker\
:
a\
=\
'\
F\
a\
i\
l\
e\
d\
\
T\
o\
\
I\
n\
s\
t\
a\
l\
l\
\
s\
p\
e\
e\
d\
t\
e\
s\
t\
-\
c\
l\
i\
\n\
L\
a\
c\
k\
i\
n\
g\
\
r\
o\
o\
t\
\
p\
e\
r\
m\
i\
s\
s\
i\
o\
n\
s\
?\
'
else\
:
try\
:
a\
,\
share\
=\
speed_test_formatter\
(
a
)
except\
:
share\
=\
None
else\
:
a\
=\
'\
M\
i\
s\
s\
i\
n\
g\
\
D\
e\
p\
e\
n\
d\
e\
n\
c\
y\
\
s\
p\
e\
e\
d\
t\
e\
s\
t\
-\
c\
l\
i\
'
finally\
:
if \
share\
:
if \
yes_or_no\
(
'\
W\
o\
u\
l\
d\
\
y\
o\
u\
\
l\
i\
k\
e\
\
f\
o\
r\
\
m\
e\
\
t\
o\
\
o\
p\
e\
n\
\
t\
h\
i\
s\
\
i\
n\
\
a\
\
b\
r\
o\
w\
s\
e\
r\
?\
'
)\
:
if \
os.name\
==\
'\
n\
t\
'\
:
os\
.\
popen\
('\
s\
t\
a\
r\
t\
\
{\
0\
}\
'\
.\
format\
(
share
)
)
elif \
os\
.\
name\
==\
'\
p\
o\
s\
i\
x\
'\
:
os\
.\
popen\
(
'\
o\
p\
e\
n\
\
{\
0\
}\
'\
.\
format\
(
share
)
)
else\
:
os\
.\
popen\
(
'\
x\
d\
g\
-\
o\
p\
e\
n\
\
{\
0\
}\
'\
.\
format\
(
share
)
)
else\
:
print\
(
a
)
print\
(
share
)
def \
speed_test_formatter\
(
a
)\
:
b\
=\
[\
'\
'\
,
'\
'\
,
'\
'
]
b\
[
0
]\
=\
a\
[
4
]\
.\
split\
(
'\
:\
'
)\
[
-1
]\
.\
strip\
(
)\
.\
strip\
('\
\'\
')
b\
[
1
]\
=\
a\
[
6
]\
.\
strip\
(
)
b\
[
2
]\
=\
a\
[
8
]\
.\
strip\
(
)
share\
=\
a\
[
-1
]
a\
=\
'\
\n\
'\
.\
join\
(
b
)
share\
=\
share\
.\
split\
(
'\
r\
e\
s\
u\
l\
t\
s\
:\
\
')\
[
-1
]\
.\
strip\
(
)
return\
a\
,\
share
def \
pip_updater\
(
)\
:
print\
(
'\
P\
l\
e\
a\
s\
e\
\
N\
o\
t\
e\
,\
\
t\
h\
i\
s\
\
h\
a\
s\
\
t\
o\
\
b\
e\
\
r\
u\
n\
\
a\
s\
\
r\
o\
o\
t\
\
o\
r\
\
i\
n\
\
a\
\
v\
e\
n\
v\
'
)
if \
not \
yes_or_no\
(
'\
w\
o\
u\
l\
d\
\
y\
o\
u\
\
l\
i\
k\
e\
\
t\
o\
\
c\
o\
n\
t\
i\
n\
u\
e\
?\
'
)\
:
return
if \
os\
.\
name\
!=\
'\
n\
t\
'\
:
if \
not \
yes_or_no\
(
'\
D\
o\
\
y\
o\
u\
\
n\
e\
e\
d\
\
s\
u\
d\
o\
?\
'
)\
:
pip_update_command\
=\
'\
p\
i\
p\
\
f\
r\
e\
e\
z\
e\
\
-\
-\
l\
o\
c\
a\
l\
\
|\
\
g\
r\
e\
p\
\
-\
v\
\
\'\
^\
\\\
-\
e\
\'\
\
|\
\
c\
u\
t\
\
-\
d\
\
=\
\
-\
f\
\
1\
\
|\
\
x\
a\
r\
g\
s\
\
-\
n\
1\
\
p\
i\
p\
\
i\
n\
s\
t\
a\
l\
l\
\
-\
U\
'
else\
:
pip_update_command\
=\
'\
p\
i\
p\
\
f\
r\
e\
e\
z\
e\
\
-\
-\
l\
o\
c\
a\
l\
\
|\
\
g\
r\
e\
p\
\
-\
v\
\
\'\
^\
\\\
-\
e\
\'\
\
|\
\
c\
u\
t\
\
-\
d\
\
=\
\
-\
f\
\
1\
\
|\
\
x\
a\
r\
g\
s\
\
-\
n\
1\
\
s\
u\
d\
o\
\
p\
i\
p\
\
i\
n\
s\
t\
a\
l\
l\
-\
U\
'
else\
:
pip_update_command\
=\
'\
p\
i\
p\
\
f\
r\
e\
e\
z\
e\
\
-\
-\
l\
o\
c\
a\
l\
\
|\
\
g\
r\
e\
p\
\
-\
v\
\
\'\
^\
\\\
-\
e\
\'\
\
|\
\
c\
u\
t\
\
-\
d\
\
=\
\
-\
f\
\
1\
\
|\
\
x\
a\
r\
g\
s\
\
-\
n\
1\
\
p\
i\
p\
\
i\
n\
s\
t\
a\
l\
l\
\
-\
U\
\
'
if \
yes_or_no\
(
'\
D\
o\
\
y\
o\
u\
\
w\
a\
n\
t\
\
t\
o\
\
i\
n\
s\
t\
a\
l\
l\
\
p\
r\
e\
\
r\
e\
l\
e\
a\
s\
e\
s\
?\
'
)\
:
pip_update_command\
+=\
'\
\
-\
-\
p\
r\
e\
\
'
x\
=\
os\
.\
popen\
(
pip_update_command
)
print\
(
'\
U\
p\
d\
a\
t\
i\
n\
g\
\
p\
i\
p\
\
p\
l\
e\
a\
s\
e\
\
w\
a\
i\
t\
.\
.\
.\
'
)
len\
(
x\
.\
readlines\
(
)
)
print\
(
'\
D\
o\
n\
e\
'
)
def \
run_bash_commands\
(
)\
:
while \
True\
:
print\
(
'\
E\
n\
t\
e\
r\
i\
n\
g\
\
B\
a\
s\
h\
\
M\
o\
d\
e\
.\
.\
.\
.\
'
)
x\
=\
input\
(
'\
C\
o\
m\
m\
a\
n\
d\
\
>\
>\
'
)
if \
x\
.\
lower\
(
)\
in \
[
'\
e\
x\
i\
t\
',
'\
d\
o\
n\
e\
',
'\
q\
u\
i\
t\
'
]\
:
return
x\
=\
os\
.\
popen\
(
x
)
print\
(
x\
.\
read\
(
)
)
def \
test_python\
(
):
print\
(
'\
e\
n\
t\
e\
r\
\
\\n\
f\
o\
r\
\
m\
u\
l\
t\
i\
-\
l\
i\
n\
e\
d\
\
c\
o\
d\
e\
'
)
while \
True\
:
try\
:
x\
=\
str\
(
input
(
'\
>\
>\
>\
\
'
)
)\
.\
strip\
()\
.\
replace\
(
'\
\\n\
',
'\
\n\
'
)
while\
x\
.\
endswith\
(
'\
\n\
'
)\
:
x\
+=\
str\
(
input\
(
'\
>\
>\
>\
\
'
)
)\
.\
strip\
(
)\
.\
replace\
(
'\
\\n\
',
'\
\n\
'
)
if\
not \
x\
.\
startswith\
(
'\
e\
x\
i\
t\
'
)\
:
exec\
(
x\
,
globals\
(
)\
,\
locals\
(
)
)
else\
:
break
except \
Exception \
as \
e\
:
print\
(
e
)
def \
exiter\
(
)\
:
print\
(
'\
E\
x\
i\
t\
i\
n\
g\
.\
.\
.\
'
)
process_killer\
(
)
exit\
(
'\
E\
x\
i\
t\
e\
d\
'
)
def \
reporthook\
(
blocknum\
,
blocksize\
,
totalsize
)\
:
readsofar\
=\
blocknum\
*\
blocksize
if \
totalsize\
>\
0\
:
percent\
=\
readsofar\
*\
1e2\
/\
totalsize
s\
=\
"\
\r\
%\
5\
.\
1\
f\
%\
%\
\
%\
*\
d\
\
/\
\
%\
d\
"\
%\
(
percent\
,
len\
(
str\
(
totalsize
)
)
,\
readsofar\
,\
totalsize
)
sys\
.\
stderr\
.\
write\
(
s
)
if \
readsofar\
>=\
totalsize\
: # near the end
sys\
.\
stderr\
.\
write\
(
"\
\n\
"
)
else\
: # total size is unknown
sys\
.\
stderr\
.\
write\
(
"\
r\
e\
a\
d\
\
%\
d\
\n\
"\
%\
(
readsofar\
,
)
)
def \
program_update\
():
try\
:
if \
os.name \
!= \
'posix':
print\
(
'\
O\
n\
l\
y\
\
w\
o\
r\
k\
i\
n\
g\
\
o\
n\
\
l\
i\
n\
u\
x\
\
s\
y\
s\
t\
e\
m\
s\
')
return
x \
=\
[
os\
.\
getcwd\
(
)\
,
0
]
while \
os\
.\
path\
.\
exists\
(
'\
t\
e\
m\
p\
{\
0\
}\
'\
.\
format\
(
x\
[
1
]
)
)\
:
x\
[
1
]\
+=\
1
temp_path \
= \
'\
t\
e\
m\
p\
{\
}\
'\
.\
format\
(
x\
[
1
]
)
urlretrieve\
(
'\
h\
t\
t\
p\
s\
:\
/\
/\
g\
i\
t\
h\
u\
b\
.\
c\
o\
m\
/\
N\
e\
k\
o\
K\
i\
t\
t\
y\
/\
F\
l\
o\
r\
a\
-\
C\
l\
i\
/\
a\
r\
c\
h\
i\
v\
e\
/\
m\
a\
s\
t\
e\
r\
.\
z\
i\
p\
'\
,
'\
m\
a\
s\
t\
e\
r\
.\
z\
i\
p\
'\
,
reporthook
)
unzip\
(
'\
m\
a\
s\
t\
e\
r\
.\
z\
i\
p\
'\
,
temp_path
)
print\
(
'\
i\
n\
s\
t\
a\
l\
l\
i\
n\
g\
'
)
command\
=\
'\
c\
d\
\
{\
0\
}\
/\
F\
l\
o\
r\
a\
-\
C\
l\
i\
-\
m\
a\
s\
t\
e\
r\
/\
\
&\
&\
\
s\
u\
d\
o\
\
s\
h\
\
s\
e\
t\
u\
p\
.\
s\
h\
'\
.\
format\
(
temp_path
)
len\
(
os\
.\
popen\
(
command
)\
.\
readlines\
(
)
)
rmtree\
(
temp_path
)
print\
(
'\
D\
o\
n\
e\
'
)
except \
Exception \
as \
e\
:
print\
(
e
)
def \
unzip\
(
source_filename\
: \
str\
,
path\
: \
str\
,
remove_zip\
: \
bool\
=\
True
)\
:
with \
zipfile\
.\
ZipFile\
(
source_filename
) \
as \
zf\
:
if \
not \
os\
.\
path\
.\
exists\
(
path
)\
:
os\
.\
mkdir\
(
path
)
zf\
.\
extractall\
(
path\
=\
path
)
if \
remove_zip\
:
os\
.\
remove\
(
source_filename
)
def \
task_manager\
(
loop\
=\
False
)\
:
processes\
=\
psutil\
.\
pids\
(
)
display\
=\
'\
{\
0\
:\
<\
1\
0\
}\
\
|\
\
{\
1\
:\
>\
4\
0\
}\
\
|\
\
{\
2\
:\
>\
8\
}\
\
|\
\
{\
3\
:\
<\
2\
2\
}\
|\
\
{\
4\
:\
>\
6\
0\
}\
\
|\
\n\
'\
.\
format\
(
'\
P\
I\
D\
'\
,
'\
N\
a\
m\
e\
'\
,
'\
C\
P\
U\
%\
'\
,
'\
M\
E\
M\
O\
R\
Y\
%\
'\
,
'\
C\
u\
r\
r\
e\
n\
t\
\
W\
o\
r\
k\
i\
n\
g\
\
D\
i\
r\
e\
c\
t\
o\
r\
y\
')
for \
p \
in \
processes\
:
try\
:
p\
=\
psutil\
.\
Process\
(
p
)
display\
+=\
'\
{\
0\
:\
<\
1\
0\
}\
\
|\
\
{\
1\
:\
>\
4\
0\
}\
\
|\
\
{\
2\
:\
>\
8\
}\
\
|\
\
{\
3\
:\
<\
2\
2\
}\
|\
\
{\
4\
:\
>\
6\
0\
}\
\
|\
\n\
'\
.\
format\
(
p\
.\
pid\
,
p\
.\
name\
(
)\
,
str\
(
p\
.\
cpu_percent\
(
)
)\
+\
'\
%\
'\
,
str\
(
p\
.\
memory_percent\
(
)
)\
+\
'\
%\
'\
,
p\
.\
cwd\
(
)
)
except\
:
pass
print\
(
display
)
if \
loop \
or \
yes_or_no\
(
'\
W\
o\
u\
l\
d\
\
Y\
o\
u\
\
l\
i\
k\
e\
\
m\
e\
\
t\
o\
\
t\
e\
r\
m\
i\
n\
a\
t\
e\
\
a\
\
p\
r\
o\
c\
e\
s\
s\
?\
\n\
'\
)\
:
print\
(
'\
E\
n\
t\
e\
r\
\
D\
o\
n\
e\
,\
\
w\
h\
e\
n\
\
y\
o\
u\
\
a\
r\
e\
\
d\
o\
n\
e\
'
)
p\
=\
input\
(
'\
P\
I\
D\
:\
\n\
>\
>\
>\
\
'
)
print\
(
p
)
if \
p\
.\
lower\
(
)\
==\
'\
d\
o\
n\
e\
'\
:
return
if \
p\
.\
lower\
(
)\
==\
'\
l\
i\
s\
t\
'\
:
processes\
=\
psutil\
.\
pids\
(
)
display\
=\
'\
{\
0\
:\
<\
1\
0\
}\
\
|\
\
{\
1\
:\
>\
4\
0\
}\
\
|\
\
{\
2\
:\
>\
8\
}\
\
|\
\
{\
3\
:\
<\
2\
2\
}\
|\
\
{\
4\
:\
>\
6\
0\
}\
\
|\
\n\
'\
.\
format\
(
'\
P\
I\
D\
'\
,
'\
N\
a\
m\
e\
'\
,
'\
C\
P\
U\
%\
'\
,
'\
M\
E\
M\
O\
R\
Y\
%\
'\
,
'\
C\
u\
r\
r\
e\
n\
t\
\
W\
o\
r\
k\
i\
n\
g\
\
D\
i\
r\
e\
c\
t\
o\
r\
y\
'
)
for \
p \
in \
processes\
:
try\
:
p\
=\
psutil\
.\
Process\
(
p
)
display\
+=\
'\
{\
0\
:\
<\
1\
0\
}\
\
|\
\
{\
1\
:\
>\
4\
0\
}\
\
|\
\
{\
2\
:\
>\
8\
}\
\
|\
{\
3\
:\
<\
2\
2\
}\
|\
\
{\
4\
:\
>\
6\
0\
}\
\
|\
\n\
'\
.\
format\
(
p\
.\
pid\
,
p\
.\
name\
(
)\
,
str\
(
p\
.\
cpu_percent\
(
)
)\
+\
'\
%\
'\
,
str\
(
p\
.\
memory_percent\
(
)
)\
+\
'\
%\
'\
,
p\
.\
cwd\
(
)
)
except\
Exception\
:
pass
p\
=\
'\
l\
i\
s\
t\
'
if \
p\
.\
lower\
(
)\
!=\
'\
l\
i\
s\
t\
'\
:
try\
:
p\
=\
psutil\
.\
Process\
(
int\
(
p
)
)
if \
os\
.\
name\
!=\
'\
n\
t\
'\
:
os\
.\
popen\
(
'\
k\
i\
l\
l\
\
{\
0\
}\
'\
.\
format\
(
p\
.\
pid
)
)
else\
:
p\
.\
kill\
(
)
p\
.\
terminate\
(
)
psutil\
.\
pids\
(
)
p\
=\
int\
(
psutil\
.\
pid
)
if\
p \
in \
psutil\
.\
pids\
(
)\
:
print\
(
'\
F\
a\
i\
l\
e\
d\
'
)
else\
:
print\
(
'\
E\
x\
i\
t\
e\
d\
'
)
except\
:
print\
(
'\
S\
o\
r\
r\
y\
,\
\
I\
\
c\
a\
n\
n\
o\
t\
\
t\
e\
r\
m\
i\
n\
a\
t\
e\
\
t\
h\
a\
t\
\
p\
r\
o\
c\
e\
s\
s\
'
)
time\
.\
sleep\
(
2
)
task_manager\
(
True
)
def \
main\
(
)\
:
print\
(
'\
P\
l\
e\
a\
s\
e\
\
S\
e\
l\
e\
c\
t\
\
a\
n\
\
o\
p\
t\
i\
o\
n\
'
)
for \
command \
in \
list_of_commands\
:
msg\
=\
'\
{\
0\
}\
.\
\
{\
1\
}\
'\
.\
format\
(
list_of_commands\
.\
index\
(
command
)\
,
command
)
print\
(
msg
)
try\
:
x\
=\
input\
(
'\
O\
p\
t\
i\
o\
n\
:\
'
)
if \
not \
x\
.\
isdigit\
(
)\
:
command\
=\
list_of_commands\
.\
index\
(
x
)
else\
:
command\
=\
list_of_commands\
[
int\
(
x
)
]
except\
:
command\
=\
None
command_handler\
(
command
)
command_dictionary\
=\
{
'\
E\
d\
i\
t\
\
C\
o\
n\
f\
i\
g\
'\
:\
edit_config\
,
'\
T\
e\
s\
t\
\
P\
y\
t\
h\
o\
n\
'\
:\
test_python\
,
'\
U\
p\
d\
a\
t\
e\
\
P\
I\
P\
\
D\
e\
p\
e\
n\
d\
e\
n\
c\
i\
e\
s\
'\
:\
pip_updater\
,
'\
s\
p\
e\
e\
d\
t\
e\
s\
t\
'\
:\
speed_test\
,
'\
s\
t\
a\
r\
t\
\
b\
o\
t\
'\
:\
bot_starter\
,
'\
k\
i\
l\
l\
\
p\
i\
d\
'\
:
process_killer\
,
'\
b\
a\
s\
h\
'\
:\
run_bash_commands\
,
'\
u\
p\
d\
a\
t\
e\
'\
:\
program_update\
,
'\
t\
a\
s\
k\
\
m\
a\
n\
a\
g\
e\
r\
'\
:\
task_manager\
}
if __name__ == '__main__':
try\
:
error\
=\
'\
N\
o\
t\
\
G\
i\
v\
e\
n\
'
move_forward\
=\
True
if \
'\
-\
d\
'\
in\
sys\
.\
argv\
or \
'\
-\
-\
d\
e\
b\
u\
g\
' \
in \
sys\
.\
argv\
:
options\
[
'\
d\
e\
b\
u\
g\
'
]\
=\
True
if \
'\
-\
-\
r\
e\
f\
r\
e\
s\
h\
' \
in \
sys\
.\
argv\
:
options\
[
'\
F\
i\
r\
s\
t\
\
S\
t\
a\
r\
t\
'
]\
=\
True
if \
'\
-\
-\
c\
o\
n\
f\
i\
g\
' \
in \
sys\
.\
argv\
:
options\
[
'\
e\
d\
i\
t\
\
c\
o\
n\
f\
i\
g\
'
]\
=\
True
get_values\
(
options\
[
'\
F\
i\
r\
s\
t\
\
S\
t\
a\
r\
t\
'
]
)
if \
'\
-\
-\
h\
e\
l\
p\
' \
in \
sys\
.\
argv\
:
move_forward\
=\
False
print\
(
'\
F\
l\
o\
r\
a\
\
C\
o\
m\
m\
a\
n\
d\
\
L\
i\
n\
e\
\
U\
t\
i\
l\
i\
t\
y\
\n\
-\
-\
d\
e\
b\
u\
g\
\
|\
|\
\
p\
r\
i\
n\
t\
s\
\
o\
u\
t\
\
e\
r\
r\
o\
s\
\n\
-\
-\
c\
o\
n\
f\
i\
g\
\
|\
|\
\
e\
d\
i\
t\
\
c\
o\
n\
f\
i\
g\
\n\
-\
-\
r\
e\
f\
r\
e\
s\
h\
\
|\
|\
\
r\
e\
s\
e\
t\
s\
\
c\
o\
n\
f\
i\
g\
u\
r\
a\
t\
i\
o\
n\
\n\
-\
-\
h\
e\
l\
p\
\
|\
|\
\
o\
u\
t\
p\
u\
t\
s\
\
t\
h\
i\
s\
\
s\
c\
r\
e\
e\
n\
'
)
if \
move_forward:
print\
(
'\
H\
e\
l\
l\
o\
'\
,
val\
[
'\
n\
a\
m\
e\
'
]
)
main\
(
)
else\
:
print\
(
'\
S\
o\
m\
e\
t\
h\
i\
n\
g\
\
w\
e\
n\
t\
\
w\
r\
o\
n\
g\
\n\
E\
r\
r\
o\
r\
:\
'\
,
error
)
except\
:
exiter\
(
)
@SamuiNe
Copy link

SamuiNe commented Nov 26, 2016

aaaaaaaaaaaaaaa

@byronvanstien
Copy link

so kawaii

@velddev
Copy link

velddev commented Sep 18, 2017

just no

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment