Last active
September 29, 2019 13:48
-
-
Save suspectpart/635f6a0674588a8016039994d94e696d to your computer and use it in GitHub Desktop.
Crystal Ball
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cmd import Cmd | |
import random | |
import string | |
import uuid | |
# noinspection PyMethodMayBeStatic,PyUnusedLocal | |
class CrystalBall(Cmd): | |
intro = 'Ask the crystal ball for some truly random things. \n\n' \ | |
'Type "help" to get some help.' | |
prompt = '(Crystal Ball ๐ฎ) ' | |
ruler = "-" | |
def default(self, arg): | |
if arg == "EOF": | |
# exit on Ctrl-D | |
return self.do_quit(arg) | |
return super().default(arg) | |
def do_uuid(self, arg): | |
"""Prints a random uuid v4""" | |
print(uuid.uuid4()) | |
def do_emoji(self, arg): | |
"""Prints a random sequence of emojis. | |
k -- length of sequence (optional) | |
""" | |
self._random_string(arg, "๐๐๐๐ฅ๐ซ๐ค๐ฆ๐จ๐ถ๐ฑ๐ฉ๐๐๐ป๐๐ธ๐ง๐๐ผ๐พ๐ต๐ป๐") | |
def do_alphanum(self, arg): | |
"""Prints a random alphanumeric sequence. | |
k -- length of sequence (optional) | |
""" | |
self._random_string(arg, string.ascii_letters + string.digits) | |
def do_numeric(self, arg): | |
"""Prints a random numeric sequence. | |
k -- length of sequence (optional) | |
""" | |
self._random_string(arg, string.digits) | |
def _random_string(self, arg, alphabet): | |
args = arg.split() | |
k = int(args[0]) if args else 16 | |
print(''.join(random.choices(alphabet, k=k))) | |
def do_exit(self, arg): | |
"""Quits the shell""" | |
return True | |
def do_quit(self, arg): | |
"""Quits the shell""" | |
return True | |
def do_q(self, arg): | |
"""Quits the shell""" | |
return True | |
if __name__ == '__main__': | |
CrystalBall().cmdloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment