excluder.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import os
  2. import crawler
  3. def add(incoming,userinput):
  4. with open(incoming, 'r') as f:
  5. lines = f.read().split()
  6. with open(incoming, 'a') as f:
  7. f.write('\n'.join([userinput + '\n']))
  8. with open(incoming, 'r') as f:
  9. lines = set(f.readlines())
  10. with open(incoming, 'w') as f:
  11. f.writelines(set(lines))
  12. crawler.sort(incoming)
  13. def add_file(incoming,excluded_in):
  14. comment_roc = ['#',';','!']
  15. data= ""
  16. with open(incoming) as fp:
  17. data = fp.read()
  18. with open(excluded_in) as fp:
  19. data2 = fp.read()
  20. data += data2
  21. with open(incoming, 'w') as fp:
  22. fp.write(data + '\n')
  23. fp.close()
  24. with open(incoming, 'r') as f:
  25. lines = f.read().split()
  26. with open(incoming, 'w') as f:
  27. for line in lines:
  28. if line.strip() and not line.startswith((tuple(comment_roc))):
  29. f.write('\n'.join([line + '\n']))
  30. with open(incoming, 'r') as f:
  31. lines = set(f.readlines())
  32. with open(incoming, 'w') as f:
  33. f.writelines(set(lines))
  34. crawler.sort(incoming)
  35. asap = input("Do You wish to Delete Input File (Y/N) : ")
  36. if asap == 'Y' or asap == 'y':
  37. os.remove(excluded_in)
  38. else:
  39. pass
  40. def remove(incoming,userinput):
  41. with open(incoming, 'r') as f:
  42. lines = f.read().split()
  43. with open(incoming, 'w') as f:
  44. for line in lines:
  45. if line.startswith(userinput) and userinput in line:
  46. f.write(line.replace(userinput ,''))
  47. elif not line.startswith(userinput):
  48. f.write('\n'.join([line + '\n']))
  49. with open(incoming ,'r') as f:
  50. lines = f.read().split()
  51. with open(incoming ,'w') as f:
  52. for line in lines:
  53. if line.strip():
  54. f.write('\n'.join([line + '\n']))
  55. with open(incoming, 'r') as f:
  56. lines = set(f.readlines())
  57. with open(incoming, 'w') as f:
  58. f.writelines(set(lines))
  59. f.close()
  60. crawler.sort(incoming)
  61. def remove_file(incoming ,removed_in):
  62. with open(removed_in ,'r') as f:
  63. stallin = f.read().split()
  64. with open(incoming, 'r') as f:
  65. lines = f.read().split()
  66. with open(incoming, 'w') as f:
  67. for line in lines:
  68. if line in stallin and line.strip() and line.startswith((tuple(stallin))):
  69. f.write(line.replace(line ,''))
  70. elif not line.startswith((tuple(stallin))):
  71. f.write('\n'.join([line + '\n']))
  72. asap = input("Do You wish to Delete Input File (Y/N) : ")
  73. if asap == 'Y' or asap == 'y':
  74. os.remove(removed_in)
  75. else:
  76. pass
  77. def search(incoming,userinput):
  78. with open(incoming, 'r') as f:
  79. lines = f.read().split()
  80. for line in lines:
  81. if userinput in line and line.endswith(userinput):
  82. print(line)