Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import os.path
- import time
- import re
- getTime = lambda: int(round(time.time() * 1000))
- output_file = 'cleared_hosts' #file where content will be placed
- start = getTime()
- def getRegex():
- regex = ''
- with open('urls_list.txt', 'r') as body: #file with list of lines to remove
- for line in body:
- regex += line.strip('\n') + '|'
- return re.compile(regex[:-1])
- def prepareHosts(regex):
- with open('hosts', 'r') as content: #file we want to remove lines from
- for line in content:
- if not regex.search(line):
- writeToFile(line)
- def writeToFile(text):
- with open(output_file, 'a') as file_:
- file_.write(text)
- if os.path.isfile(output_file):
- os.remove(output_file)
- prepareHosts(getRegex())
- print("Took {0}ms".format(getTime() - start))
Advertisement
Add Comment
Please, Sign In to add comment