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.
16 changes: 16 additions & 0 deletions homeworks/At0mn1yIvan/5/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from tskInput import com_input


def main():
try:
com_input()
except Exception as ex:
print('Something went wrong.', ex)


if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
print()
print('Shutting down, bye!')
37 changes: 37 additions & 0 deletions homeworks/At0mn1yIvan/5/cmnds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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 task(action: str, text: str = None) -> None:
if action == 'help':
functions[action]()
else:
functions[action](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'")


functions = {'highlight': Highlight, 'cowsay': Cowsay, 'time': Time, 'help': Help} # noqa: E501
16 changes: 16 additions & 0 deletions homeworks/At0mn1yIvan/5/tskInput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import argparse

from cmnds import functions, task


def com_input():
parser = argparse.ArgumentParser()
parser.add_argument('action', help='Input action.', choices=functions)
parser.add_argument('text', help="highlight 'any text'/cowsay 'any text'/time 'Region/City'") # noqa: E501
args = parser.parse_args()

try:
task(args.action, args.text)
except Exception as ex:
task('help')
raise ex