Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from .cmdInput import cmd_input


def main():
try:
cmd_input()
except Exception as ex:
print('You have done something wrong!', ex)


if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print()
print('Shutting down, bye!')

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import argparse

from .command import command, functions


def cmd_input():
"""Input method."""
parser = argparse.ArgumentParser()
parser.add_argument('operation', help='Input command', choices=functions)
parser.add_argument('parameter', help="'Any text' or 'Region/City'")
args = parser.parse_args()

try:
command(args.operation, args.parameter)
except Exception as ex:
command('help')
raise ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

from datetime import datetime

import pytz
from cowpy import cow
from pygments import highlight
from pygments.formatters import TerminalFormatter
from pygments.lexers import PythonLexer


def command(operation: str, text: str = None) -> None:
functions[operation]() if operation == 'help' else functions[operation](text)


def highlight_(code: str) -> None:
print(highlight(code, PythonLexer(), TerminalFormatter()))


def cowsay_(text: str) -> None:
print(cow.milk_random_cow(text))


def time_(timezone: str) -> None:
local_date = datetime.now(pytz.timezone(timezone))
print("{0} {1}".format(local_date.date(), local_date.time()))


def help_() -> None:
print('EXAMPLE COMMAND:')
print(" highlight 'any text'")
print(" cowsay 'any text'")
print(" time 'Region/City' (example: Europe/Moscow)")


functions = {'highlight': highlight_, 'cowsay': cowsay_, 'time': time_, 'help': help_}
Loading