filters-maker/excluder.py

88 lines
2.8 KiB
Python
Raw Normal View History

import os
2021-08-03 12:04:59 +00:00
import crawler
2021-08-03 11:56:08 +00:00
def add(incoming,userinput):
2021-08-03 11:56:08 +00:00
with open(incoming, 'r') as f:
lines = f.read().split()
with open(incoming, 'a') as f:
f.write('\n'.join([userinput + '\n']))
2021-08-03 11:56:08 +00:00
with open(incoming, 'r') as f:
lines = set(f.readlines())
with open(incoming, 'w') as f:
f.writelines(set(lines))
2021-08-03 12:04:59 +00:00
crawler.sort(incoming)
2021-08-03 11:56:08 +00:00
def add_file(incoming,excluded_in):
2021-08-11 05:21:31 +00:00
comment_roc = ['#',';','!']
2021-08-07 04:36:18 +00:00
data= ""
with open(incoming) as fp:
data = fp.read()
with open(excluded_in) as fp:
data2 = fp.read()
data += data2
with open(incoming, 'w') as fp:
2021-08-07 04:36:18 +00:00
fp.write(data + '\n')
fp.close()
with open(incoming, 'r') as f:
lines = f.read().split()
with open(incoming, 'w') as f:
for line in lines:
2021-08-11 05:21:31 +00:00
if line.strip() and not line.startswith((tuple(comment_roc))):
f.write('\n'.join([line + '\n']))
2021-08-11 05:50:54 +00:00
with open(incoming, 'r') as f:
lines = set(f.readlines())
with open(incoming, 'w') as f:
f.writelines(set(lines))
crawler.sort(incoming)
2021-08-14 10:44:00 +00:00
asap = input("Do You wish to Delete Input File (Y/N) \n")
if asap == 'Y' or asap == 'y':
os.remove(excluded_in)
else:
pass
2021-08-10 05:26:44 +00:00
def remove(incoming,userinput):
2021-08-10 05:26:44 +00:00
with open(incoming, 'r') as f:
lines = f.read().split()
with open(incoming, 'w') as f:
for line in lines:
if line.startswith(userinput) and userinput in line:
f.write(line.replace(userinput ,''))
elif not line.startswith(userinput):
2021-08-10 05:26:44 +00:00
f.write('\n'.join([line + '\n']))
with open(incoming ,'r') as f:
lines = f.read().split()
with open(incoming ,'w') as f:
for line in lines:
if line.strip():
f.write('\n'.join([line + '\n']))
with open(incoming, 'r') as f:
lines = set(f.readlines())
with open(incoming, 'w') as f:
f.writelines(set(lines))
f.close()
crawler.sort(incoming)
def remove_file(incoming ,removed_in):
with open(removed_in ,'r') as f:
stallin = f.read().split()
with open(incoming, 'r') as f:
lines = f.read().split()
with open(incoming, 'w') as f:
for line in lines:
if line in stallin and line.strip() and line.startswith((tuple(stallin))):
f.write(line.replace(line ,''))
elif not line.startswith((tuple(stallin))):
f.write('\n'.join([line + '\n']))
2021-08-14 10:44:00 +00:00
asap = input("Do You wish to Delete Input File (Y/N) \n")
if asap == 'Y' or asap == 'y':
os.remove(removed_in)
else:
pass
def search(incoming,userinput):
with open(incoming, 'r') as f:
lines = f.read().split()
for line in lines:
if userinput in line and line.endswith(userinput):
print(line)