67 lines
1.8 KiB
Python
67 lines
1.8 KiB
Python
|
import sys
|
|||
|
|
|||
|
def make_crazy_lib(filename):
|
|||
|
try:
|
|||
|
file = open(filename, 'r')
|
|||
|
|
|||
|
text = ''
|
|||
|
|
|||
|
for line in file:
|
|||
|
text = text + process_line(line) + '\n'
|
|||
|
|
|||
|
file.close()
|
|||
|
|
|||
|
return text
|
|||
|
except FileNotFoundError:
|
|||
|
print('Не удалось найти файл', filename + '.')
|
|||
|
except IsADirectoryError:
|
|||
|
print('Вообще-то,', filename, '- это каталог.')
|
|||
|
except:
|
|||
|
print('Не удалось прочитать файл', filename)
|
|||
|
|
|||
|
def save_crazy_lib(filename, text):
|
|||
|
file = open(filename, "w")
|
|||
|
|
|||
|
file.write(text)
|
|||
|
file.close()
|
|||
|
|
|||
|
placeholders = ['СУЩЕСТВИТЕЛЬНОЕ', 'ПРИЛАГАТЕЛЬНОЕ', 'ГЛАГОЛ']
|
|||
|
|
|||
|
def process_line(line):
|
|||
|
global placeholders
|
|||
|
processed_line = ''
|
|||
|
symbol = ''
|
|||
|
words = line.split()
|
|||
|
for word in words:
|
|||
|
stripped = word.strip('.,;?!')
|
|||
|
if stripped in placeholders:
|
|||
|
answer = input(f'Введите {stripped}: ')
|
|||
|
processed_line = processed_line + answer + ''
|
|||
|
if word[-1] in '.,;?!':
|
|||
|
for char in word:
|
|||
|
if char in '.,;?!':
|
|||
|
symbol = symbol + char + ''
|
|||
|
processed_line = processed_line + symbol + ' '
|
|||
|
else:
|
|||
|
processed_line = processed_line + ' '
|
|||
|
else:
|
|||
|
processed_line = processed_line + word + ' '
|
|||
|
return processed_line
|
|||
|
|
|||
|
def main():
|
|||
|
if len(sys.argv) != 2:
|
|||
|
filename = 'lib.txt'
|
|||
|
lib = make_crazy_lib(filename)
|
|||
|
# print(lib)
|
|||
|
if (lib != None):
|
|||
|
save_crazy_lib('carzy_' + filename, lib)
|
|||
|
else:
|
|||
|
filename = sys.argv[1]
|
|||
|
lib = make_crazy_lib(filename)
|
|||
|
# print(lib)
|
|||
|
if (lib != None):
|
|||
|
save_crazy_lib('carzy_' + filename, lib)
|
|||
|
|
|||
|
|
|||
|
if __name__ == '__main__':
|
|||
|
main()
|