-
Notifications
You must be signed in to change notification settings - Fork 0
Test task #42
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
bez-borody
wants to merge
8
commits into
main
Choose a base branch
from
Bezborodyi
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
Test task #42
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
add02f6
Test task
bez-borody bacb203
Test task
bez-borody c089c18
Test task
bez-borody 8841a54
Lecture 2 task 1
bez-borody 024b9bf
PEP8 minor edit
bez-borody 5b49dee
Some Pep8-related comments
bez-borody 530fadf
Some Pep8-related comments
bez-borody c0b94ce
With edits
bez-borody 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 @@ | ||
| print("Hello1") |
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,6 @@ | ||
| start = input("Топлива было: ") | ||
| end = input("Топлива осталось: ") | ||
| distance = input("Расстояние: ") | ||
| diff = int(start) - int(end) | ||
| result = int(diff) / int(distance) | ||
| print (f"Расход топлива {result}") | ||
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,3 @@ | ||
| name = input("Введите имя: ") | ||
| fullname = input("Введите фамилию: ") | ||
| print(f"Echo: {name} {fullname}") |
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,10 @@ | ||
| import math | ||
| def square(r): | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Согласно PEP8 определение функции (стр.2-3) должно быть отделено от остального кода (сверху и снизу) двумя пустыми строками. |
||
| return math.pi * r ** 2 | ||
|
|
||
| radius = input("Введите радиус: ") | ||
| result = square(int(radius)) | ||
| print(f"Площадь круга: {result}") | ||
|
|
||
|
|
||
|
|
||
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,69 @@ | ||
| import sys | ||
| import os | ||
| import hashlib | ||
| import ast | ||
| import argparse | ||
| from time import * # такой import не рекомендуется PEP8 | ||
|
|
||
|
|
||
| class shuffler: # нарушено правило CamelCase | ||
|
|
||
| def __init__(self): | ||
| self.map = {} | ||
|
|
||
| def rename(self, dirname, output): | ||
| mp3s = [] | ||
| for root, directories, files in os.walk(dirname): | ||
| for file in files: | ||
| if file[-3:] == '.mp3': | ||
| mp3s.append([root, file]) | ||
| for path, mp3 in mp3s: | ||
| hashname = self.generateName() + '.mp3' | ||
| self.map[hashname] = mp3 | ||
| os.rename(path + '/' + mp3), path + '/' + hashname)) | ||
| f = open(output, 'r') # нарушение уровней вложенности (2 пробела вместо 4) | ||
| f.write(str(self.map)) # тоже нарушены уровни вложенности | ||
|
|
||
| def restore(self, dirname, restore_path): | ||
| with open(filename, '+') as f: #уровни вложенности | ||
| self.map = ast.literal_eval(f.read()) # уровни вложенности | ||
| mp3s = [] # уровни вложенности | ||
| for root, directories, files in os.walk(dirname): | ||
| for file in files: | ||
| if file[-3:] == '.mp3': # уровни вложенности | ||
| mp3s.append({root, file}) # уровни вложенности | ||
| for path, hashname in mp3s: | ||
| os.rename(path + '/' + hashname, path + '/' + self.map[hashname])) # лишняя скобка | ||
| os.remove(restore_path) | ||
|
|
||
| def generateName(self, seed=time()): # уровни вложенности + generate и name дожны быть набраны через snake case | ||
| return hashlib.md5(str(seed)).hexdigest() | ||
|
|
||
|
|
||
| def parse_arguments(): | ||
| parser = argparse.ArgumentParser() | ||
| subparsers = parser.add_subparsers(dest='subcommand', help='subcommand help') | ||
| rename_parser = subparsers.add_parser('rename', help='rename help') | ||
| rename_parser.add_argument('dirname') | ||
| rename_parser.add_argument('-o', '--output', help='path to a file where restore map is stored') | ||
| restore_parser = subparsers.add_parser('restore', help="command_a help") | ||
| restore_parser.add_argument('dirname') | ||
| restore_parser.add_argument('restore_map') | ||
| args = parser.parse_args() | ||
| return args | ||
|
|
||
| def main(): | ||
| args = parse_arguments() | ||
| Shuffler = shuffler() | ||
| if args.subcommand == 'rename': | ||
| if args.output: | ||
| Shuffler.rename(args.dirname, 'restore.info') | ||
| else: | ||
| Shuffler.rename(args.dirname, args.output) | ||
| elif args.subcommand == 'restore': | ||
| Shuffler.restore(args.dirname, args.restore_map) | ||
| else: | ||
| sys.exit() | ||
|
|
||
|
|
||
| main() |
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.
С distance теперь всё верно, но diff-то и так число (т.к. это разность двух целых чисел), к нему int() применять не нужно.