Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #7.1
- import re
- def replace(filePath, text, subs, flags=0):
- with open(file_path, "r+") as file:
- # read the file contents
- file_contents = file.read()
- text_pattern = re.compile(re.escape(text), flags)
- file_contents = text_pattern.sub(subs, file_contents)
- file.seek(0)
- file.truncate()
- file.write(file_contents)
- f = open('/Users/alexsandrgubich/Downloads/кондуит 2022 - Преподаватели и ассистенты (1).tsv','r+')
- emails =[]
- while True:
- line = f.readline()
- if line=='':
- break
- result = re.search("[^|\w](\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)", line)
- if result!= None:
- emails.append(result.group())
- emails.append('asgubich@edu.hse.ru')
- f.close()
- f = open('/Users/alexsandrgubich/Downloads/кондуит 2022 - Преподаватели и ассистенты.tsv','r+')
- for email in emails:
- if bool(re.search("@edu.hse.ru|@hse.ru",email) )== True:
- #
- emails.pop(emails.index(email))
- else:
- pass
- if bool(re.search("@edu.hse.ru|@hse.ru",emails[-1]) )== True:
- emails.pop(emails.index(emails[-1]))
- if bool(re.search("@edu.hse.ru|@hse.ru", emails[-2])) == True:
- emails.pop(emails.index(emails[-2]))
- f.close()
- file_path = "/Users/alexsandrgubich/Downloads/кондуит 2022 - Преподаватели и ассистенты (1).tsv"
- text = ""
- subs = "Pr1v@cY REstorED"
- for i in emails:
- replace(file_path,i,subs)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement