-
Notifications
You must be signed in to change notification settings - Fork 39
Borisov Saveliy - hw5 (my-awesome-script) #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Amazingkivas
wants to merge
12
commits into
sobolevn:main
Choose a base branch
from
Amazingkivas:new_branch_4
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
616cb02
Homework_1
Amazingkivas 8995c77
Homework_1
Amazingkivas 3f1642b
Homework2
Amazingkivas 681c4c4
Adjustment for PEP8
Amazingkivas 22d7dde
add: docstring and zip, fix: exceptions check, arg_types check and va…
Amazingkivas 866b756
homework_4
Amazingkivas f69f626
Delete TheContractDecorator.py
Amazingkivas 3737ff2
Update __main__.py
Amazingkivas c2f86e9
add help
Amazingkivas 239e252
Merge branch 'new_branch_4' of https://github.com/Amazingkivas/unn-py…
Amazingkivas 94f4a66
fix formatter
Amazingkivas 20c6a93
Merge branch 'sobolevn:main' into new_branch_4
Amazingkivas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Класс списков | ||
|
|
||
| class Array(object): | ||
| def __init__(self, *args): | ||
| self._data = args | ||
|
|
||
| def append(self, item): | ||
| self._data += (item,) | ||
|
|
||
| def __add__(self, other): | ||
| result = Array() | ||
| result._data = self._data + other._data | ||
| return result | ||
|
|
||
| def __len__(self): | ||
| return len(self._data) | ||
|
|
||
| def index(self, item): | ||
| if item in self._data: | ||
| return self._data.index(item) | ||
| else: | ||
| return -1 | ||
|
|
||
| def __iter__(self): | ||
| return iter(self._data) | ||
|
|
||
| def __getitem__(self, index): | ||
| return self._data[index] | ||
|
|
||
| def __str__(self): | ||
| return str(self._data) | ||
15 changes: 15 additions & 0 deletions
15
homeworks/Amazingkivas/4/my-awesome-script/my_awesome_script/__main__.py
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| """Main program.""" | ||
| from my_awesome_script.parser import create_parser | ||
|
|
||
|
|
||
| def main(): | ||
| """ | ||
| Call the parser. | ||
|
|
||
| :return: | ||
| """ | ||
| create_parser() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() |
60 changes: 60 additions & 0 deletions
60
homeworks/Amazingkivas/4/my-awesome-script/my_awesome_script/commands.py
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| """Commands for the script.""" | ||
|
|
||
| from datetime import datetime | ||
|
|
||
| from cowpy.cow import Cowacter | ||
| from pygments import highlight as hl | ||
| from pygments.formatters import get_formatter_by_name | ||
| from pygments.lexers import get_lexer_by_name | ||
| from pytz import timezone | ||
|
|
||
|
|
||
| def run_command(command: str): | ||
| """ | ||
| Select command. | ||
|
|
||
| Args: | ||
| command: command name | ||
|
|
||
| Returns: | ||
| :return: selected command | ||
| """ | ||
| return commands[command] | ||
|
|
||
|
|
||
| def highlight(code: str): | ||
| """ | ||
| Highlight code. | ||
|
|
||
| Args: | ||
| code: code to highlight | ||
| """ | ||
| this_lexer = get_lexer_by_name('python') | ||
| this_formatter = get_formatter_by_name('terminal') | ||
| print(hl(code, lexer=this_lexer, formatter=this_formatter)) # noqa: WPS421 | ||
|
|
||
|
|
||
| def cowsay(text: str): | ||
| """ | ||
| Make the cow talk. | ||
|
|
||
| Args: | ||
| text: text that the cow say | ||
| """ | ||
| cow = Cowacter() | ||
| print(cow.milk(text)) # noqa: WPS421 | ||
|
|
||
|
|
||
| def time(region: str): | ||
| """ | ||
| Show time in the region. | ||
|
|
||
| Args: | ||
| region: selected region | ||
| """ | ||
| ftime = '%H:%M:%S' | ||
| time_zone = timezone(region) | ||
| print(datetime.now(time_zone).strftime(ftime)) # noqa: WPS421 | ||
|
|
||
|
|
||
| commands = {'highlight': highlight, 'cowsay': cowsay, 'time': time} |
25 changes: 25 additions & 0 deletions
25
homeworks/Amazingkivas/4/my-awesome-script/my_awesome_script/parser.py
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| """Poetry shell parser.""" | ||
| from argparse import ArgumentParser | ||
|
|
||
| from my_awesome_script.commands import run_command | ||
|
|
||
|
|
||
| def create_parser(): | ||
| """ | ||
| Create a poetry shell parser. | ||
|
|
||
| :return: | ||
| """ | ||
| parser = ArgumentParser() | ||
| parser.add_argument('command', type=str, help=', '.join(commands)) | ||
| parser.add_argument('parameter', type=str, help=', '.join(comm_param)) | ||
| args = parser.parse_args() | ||
|
|
||
| command = args.command | ||
| parameter = args.parameter | ||
|
|
||
| run_command(command)(parameter) | ||
|
|
||
|
|
||
| commands = ('highlight', 'cowsay', 'time') | ||
| comm_param = ('code to highlight', 'text that the cow say', 'selected region') |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just FYI - время добавления линейное тк происходит копирование (тк tuple неизменяемый)