Guest User

Untitled

a guest
Feb 7th, 2021
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | None | 0 0
  1. def email_gen(list_of_names):
  2.     '''
  3.    Функция принимает список списков [['Имя_1', 'Фамилия_1'], ..., ['Имя_N', 'Фамилия_N']]
  4.    Создается пустой список emails, который в ходе выполнения, заполнится почтовыми адресами.
  5.    Идет проверка на совпадение создоваемого адреса с существующими.
  6.    Если имена и фамилии сотрудников совпадают, к первой букве имени добавляется вторая и т.д.
  7.    Заносит полученный адресс в список emails и возваращает его.
  8.    '''
  9.     emails = []
  10.     letter = 1
  11.     for i in list_of_names:
  12.         if i[1] + '.' + i[0][0:letter] + '@company.io' in emails:
  13.             letter += 1
  14.         emails.append(i[1] + '.' + i[0][0:letter] + '@company.io')
  15.     return emails
  16.  
  17. task_file = open('task_file.txt', 'r')
  18. text = task_file.read().split('\n')
  19. task_file.close()
  20. text_person = []
  21. [text_person.append(n.split(', ')) for n in text]
  22. first_last_name = []
  23. for j in range(1, len(text_person) - 1):
  24.     first_last_name.append((text_person[j][1] + '/' + text_person[j][2]).split('/'))
  25. email = email_gen(first_last_name)
  26. task_file_valid = open('task_file_valid.txt', 'w')
  27. task_file_invalid = open('task_file_invalid.txt', 'w')
  28. task_file_valid.write(text[0] + '\n')
  29. task_file_invalid.write(text[0] + '\n')
  30. for j in range(1, len(text) - 1):
  31.     if len(text_person[j][1]) != 0 \
  32.             and text_person[j][1].isalpha() \
  33.             and 'wf' not in text_person[j][1] \
  34.             and len(text_person[j][2]) != 0 \
  35.             and text_person[j][2].isalpha() \
  36.             and 'wf' not in text_person[j][2] \
  37.             and text_person[j][1] != text_person[j][2] \
  38.             and len(text_person[j][3]) == 7 \
  39.             and text_person[j][3].isdigit() \
  40.             and int(text_person[j][3]) != 0 \
  41.             and len(text_person[j][4]) != 0:
  42.         task_file_valid.write(email[j-1] + text[j] + '\n')
  43.     else:
  44.         task_file_invalid.write(text[j] + '\n')
  45. task_file_valid.close()
  46. task_file_invalid.close()
Advertisement
Add Comment
Please, Sign In to add comment