Created
September 29, 2016 13:13
-
-
Save mkows/a732d5137e3203b7d7c586f6248bf322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This script creates a file with entries from 'file_all_entries_path' file that are | |
# not blacklisted by entries in 'blacklisted_entries_path' file. | |
# | |
# Usage: | |
# python remove-blacklisted.py | |
import datetime | |
import time | |
def build_timestamp(): | |
t = time.time() | |
return datetime.datetime.fromtimestamp(t).strftime('%Y%m%d-%H%M%S') | |
def blacklisted_by_arr(e, arr): | |
for a in arr: | |
if a.strip() in e.strip(): | |
return True | |
return False | |
file_all_entries_path = 'all-lob-control.txt' | |
blacklisted_entries_path = 'lob-control-remove.txt' | |
output_file_path = 'only-wanted-entries-' + build_timestamp() + '.txt' | |
control_all_file = open(file_all_entries_path, 'r') | |
blacklisted_entries_file = open(blacklisted_entries_path, 'r') | |
output_file = open(output_file_path, 'w') | |
control_all = control_all_file.read().splitlines() | |
control_all_file.close() | |
blacklisted_entries = blacklisted_entries_file.read().splitlines() | |
blacklisted_entries_file.close() | |
size_a = len(control_all) | |
size_b = len(blacklisted_entries) | |
print str(size_a) + ' <- size' | |
print str(size_b) + ' <- remove size' | |
print str(size_a - size_b) + ' <- expected' | |
for line in control_all: | |
if not blacklisted_by_arr(line, blacklisted_entries): | |
output_file.write(line + '\n') | |
else: | |
print '- ' + line | |
output_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment