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