Guest User

Untitled

a guest
Jan 21st, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. # I downloaded tags from booru and then also ran them through the WD tagger. Not copy, not prepend, not append — I want to MERGE. Without duplicate tags.
  2. # i love github copilot
  3.  
  4. import sys
  5. import re
  6.  
  7. if len(sys.argv) < 3:
  8.     print("Usage: python3 merge.py [file1] [file2]")
  9.     exit()
  10.  
  11. file1 = sys.argv[1]
  12. file2 = sys.argv[2]
  13.  
  14. with open(file1, "r") as f:
  15.     tags1 = f.readlines()
  16.  
  17. with open(file2, "r") as f:
  18.     tags2 = f.readlines()
  19.  
  20. # tags are split by comma
  21. tags1 = re.split(", ", tags1[0])
  22. tags2 = re.split(", ", tags2[0])
  23.  
  24. tags1 = set(tags1)
  25. tags2 = set(tags2)
  26.  
  27. tags = tags1.union(tags2)
  28.  
  29. print(tags)
  30. # print to new file
  31. with open("merged.txt", "w") as f:
  32.     f.write(", ".join(tags))
Advertisement
Add Comment
Please, Sign In to add comment