-
Notifications
You must be signed in to change notification settings - Fork 0
text lec 9-10 #92
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
Ibryanova
wants to merge
2
commits into
main
Choose a base branch
from
Ibryanova_branch
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
text lec 9-10 #92
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,10 @@ | ||
| while True: | ||
| match input("Введите Ваш вопрос: "): | ||
| case "Привет!": | ||
| print("Привет!") | ||
| case "Как дела?": | ||
| print("Хорошо") | ||
| case "Какая сегодня погода?": | ||
| print("Холод. Осень") | ||
| case _: | ||
| print("Вопрос некорректен, попробуйте сформулировать его по-другому") |
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,4 @@ | ||
| lst = ["10", "5", "a", "3", "b"] | ||
| new_lst = [x*x for i in lst if i.isdecimal() and (x := int(i)) * 2] | ||
|
|
||
| print(new_lst) |
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,36 @@ | ||
| import socket | ||
|
|
||
|
|
||
| server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
| host = '127.0.0.1' | ||
| port = 147 | ||
| cip = { | ||
| 'q': 'й', | ||
| 'w': 'ц', | ||
| 'e': 'у', | ||
| 'r': 'к', | ||
| 't': 'е', | ||
| 'y': 'н', | ||
| } | ||
|
|
||
| server.bind((host, port)) | ||
| server.listen(5) | ||
|
|
||
| while True: | ||
| conn, addr = server.accept() | ||
| s = conn.recv(2024).decode() | ||
| print(f'Получено "{"".join(s)}" от клиента {addr}.') | ||
|
|
||
| res = [] | ||
| key = {v: k for k, v in cip.items()} | ||
| for i in s: | ||
| try: | ||
| res.append(key[i]) | ||
| except KeyError: | ||
| print('ошибка') | ||
|
|
||
|
|
||
| conn.send((''.join(res)).encode()) | ||
| print('Успешно') | ||
| conn.close() | ||
| server.close() |
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,12 @@ | ||
| import socket | ||
|
|
||
|
|
||
| host = '127.0.0.1.' | ||
| port = 147 | ||
|
|
||
| client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
| client.connect((host, port)) | ||
| client.send('qwerty'.encode()) | ||
| print(f'Получено сообщение: {client.recv(1024).decode()}') | ||
|
|
||
| client.close() |
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,35 @@ | ||
| import random | ||
| import pickle | ||
|
|
||
|
|
||
| class Human: | ||
|
|
||
| def __init__(self, name, surname, age, place): | ||
| self._name = name | ||
| self._surname = surname | ||
| self._age = age | ||
| self._place = place | ||
|
|
||
|
|
||
| def generator_name(s): | ||
| lst = [] | ||
| name = ("Иван", "Антон", "Олег", "Дмитрий", "Сергей") | ||
| surname = ("Иванов", "Антонов", "Дмитров", "Петров", "Егоров") | ||
| place = ("Москва", "Питер", "Севастополь", "Калининград", "Выборг") | ||
| for i in range(s): | ||
| h = Human(random.choice(name), | ||
| random.choice(surname), | ||
| random.randint(20, 50), | ||
| random.choice(place)) | ||
| lst.append(h) | ||
| with open("human.data", "wb") as f: | ||
| pickle.dump(lst, f) | ||
|
|
||
|
|
||
| def human_deser(): | ||
| with open("human.data", "rb") as f: | ||
| return pickle.load(f) | ||
|
|
||
|
|
||
| generator_name(4) | ||
| print(human_deser()) |
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,8 @@ | ||
| import re | ||
|
|
||
|
|
||
| with open(r'../../README.md') as f: | ||
| pattern = re.compile(r"git [a-z]+\w\b") | ||
| for line in f: | ||
| res = re.findall(pattern, line) | ||
| print(res) |
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,14 @@ | ||
| import datetime as dt | ||
|
|
||
|
|
||
| def work_days(date1, date2): | ||
| date_s = dt.datetime.strptime(date1, '%d.%m.%Y') | ||
| date_e = dt.datetime.strptime(date2, '%d.%m.%Y') | ||
| count = 0 | ||
| while date_s < date_e: | ||
| if date_s.isoweekday() < 6: | ||
| count += 1 | ||
| date_s += dt.timedelta(days=1) | ||
| return count | ||
|
|
||
| print(work_days('01.10.2022', '20.10.2022')) |
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,11 @@ | ||
| from urllib import request | ||
| import re | ||
|
|
||
|
|
||
| req = request.Request('http://google.com') | ||
| response = request.urlopen(req) | ||
| web_page = response.read().decode() | ||
|
|
||
| s = re.compile(r'https[\/\:a-zA-Z\.\d\?\=]+[^\":]') | ||
| res = re.findall(s, web_page) | ||
| print(res) | ||
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,72 @@ | ||
| import sys | ||
| import os | ||
| import hashlib | ||
| import ast | ||
| import argparse | ||
| from time import *# не корректно записано, должно быть import datetime as dt | ||
|
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. Нет, здесь ошибка в другом. datetime и time - разные библиотеки. |
||
|
|
||
|
|
||
| class shuffler:# класс с загл буквы | ||
|
|
||
| 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))# лишняя закрыв скобка у mp3 и hashname | ||
| f = open(output, 'r')#файл нужно откр и на запись если f.write(str(self.map)) | ||
| f.write(str(self.map))# не закрыли файл | ||
|
|
||
| def restore(self, dirname, restore_path): | ||
| with open(filename, '+') as f:#файл откр на чтение и запись, но его только читают | ||
| self.map = ast.literal_eval(f.read())#нет связи между f и self.map | ||
|
Ibryanova marked this conversation as resolved.
|
||
| 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()): | ||
| 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.
Надо не только ссылки найти, но и проверить их работоспособность.