Merge branch 'implement-hacker-easter-egg'

This commit is contained in:
Marcel Schwarz 2020-03-21 23:49:43 +01:00
commit 1796a152ab
3 changed files with 61 additions and 1 deletions

View File

@ -6,6 +6,7 @@ from modules.swap.SwapModule import SwapModule
from modules.systemupdate.Systemupdate import Systemupdate from modules.systemupdate.Systemupdate import Systemupdate
from modules.vim.VimModule import VimModule from modules.vim.VimModule import VimModule
from modules.teamspeak.Teamspeak import Teamspeak from modules.teamspeak.Teamspeak import Teamspeak
from modules.hacker.Hacker import Hacker
modules = { modules = {
"helloworld": HelloWorld().run, "helloworld": HelloWorld().run,
@ -13,7 +14,8 @@ modules = {
"swap": SwapModule().run, "swap": SwapModule().run,
"update": Systemupdate().run, "update": Systemupdate().run,
"vim": VimModule().run, "vim": VimModule().run,
"teamspeak": Teamspeak "teamspeak": Teamspeak,
"hacker": Hacker
} }
fire.Fire(modules) fire.Fire(modules)

29
modules/hacker/Hacker.py Normal file
View File

@ -0,0 +1,29 @@
import subprocess
from os import path
import os
import random
class Hacker:
def run_bash(self):
try:
subprocess.run("bash hacker.sh", shell=True, cwd=path.dirname(__file__))
except KeyboardInterrupt:
pass
def run_py(self):
columns = int(os.popen('stty size', 'r').read().split()[1]) # length of current line
try:
while True:
num_to_show = random.randint(0, 1)
count = random.randint(3, columns // 20)
hacker = " " * columns
for i in range(count):
pos = random.randint(0, columns)
hacker = hacker[:pos] + str(num_to_show) + hacker[pos+1:]
print("\033[92m" + hacker)
except KeyboardInterrupt:
print(columns)
print("Finished")
print("\033[0m")

29
modules/hacker/hacker.sh Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env bash
width="$(tput cols)"
width=$((width / 4))
printf "$width"
printf "\e[32m\n"
while :
do
for ((i=1;i<=width;i++))
do
((r = $RANDOM % 2))
if (($RANDOM % 5 == 1))
then
if (($RANDOM % 4 == 1))
then
v+="\e[1m $r "
else
v+="\e[2m $r "
fi
else
v+=" "
fi
done
printf "$v\n"
v=""
done
;;