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.
9 changes: 9 additions & 0 deletions homeworks/DDYunin/5/my_awesome_script/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from my_awesome_script.input_cmd import parse_cmd_input


def main():
parse_cmd_input()


if __name__ == '__main__':
main()
31 changes: 31 additions & 0 deletions homeworks/DDYunin/5/my_awesome_script/commands.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytz
from pygments import highlight
from pygments.formatters import TerminalFormatter
from pygments.lexers import PythonLexer
from cowsay import turkey
from datetime import datetime


def selected_command(command, parametr=None):
all_commands[command](parametr)


def command_highlight(text):
print(highlight(text, PythonLexer(), TerminalFormatter()))


def command_cowsay(phrase):
print(turkey(phrase))


def command_time(area):
city = pytz.timezone(area)
local_time = datetime.now(city)
print('Date: {0} \nTime: {1}'.format(local_time.date(), local_time.time()))


all_commands = {
'highlight': command_highlight,
'cowsay': command_cowsay,
'time': command_time,
}
24 changes: 24 additions & 0 deletions homeworks/DDYunin/5/my_awesome_script/input_cmd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import argparse

from my_awesome_script.commands import selected_command


def parse_cmd_input():
parser = argparse.ArgumentParser()
parser.add_argument('command', type=str, choices=[
'highlight',
'cowsay',
'time',
'help',
],
help='''1) Command: highlight\n
2) Command: cowsay\n
3) Command: time\n''',
)
parser.add_argument('parametr', type=str, help='''1) Argument: 'any text'\n
2) Argument: 'any text'\n
3) Argument: 'Region/City
(example: Europe/Moscow)\n''',
)
pars_args = parser.parse_args()
selected_command(pars_args.command, pars_args.parametr)
323 changes: 323 additions & 0 deletions homeworks/DDYunin/5/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading