Forgetitg59-

Untitled

Jan 20th, 2026
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import filedialog, messagebox
  3. import re
  4. import threading
  5.  
  6. def browse_input():
  7. path = filedialog.askopenfilename(filetypes=[("ULP files", "*.ulp"), ("All files", "*.*")])
  8. if path:
  9. input_entry.delete(0, tk.END)
  10. input_entry.insert(0, path)
  11.  
  12. def browse_output():
  13. path = filedialog.asksaveasfilename(defaultextension=".txt",
  14. filetypes=[("Text files", "*.txt")])
  15. if path:
  16. output_entry.delete(0, tk.END)
  17. output_entry.insert(0, path)
  18.  
  19. def run_extractor():
  20. input_file = input_entry.get().strip()
  21. output_file = output_entry.get().strip()
  22. pattern = regex_entry.get().strip()
  23.  
  24. if not input_file or not output_file or not pattern:
  25. messagebox.showerror("Fout", "Vul alles in.")
  26. return
  27.  
  28. try:
  29. regex = re.compile(pattern, re.IGNORECASE)
  30. except re.error:
  31. messagebox.showerror("Fout", "Ongeldige regex.")
  32. return
  33.  
  34. start_button.config(state=tk.DISABLED)
  35. status_label.config(text="Bezig...")
  36.  
  37. def task():
  38. seen = set()
  39. processed = 0
  40. written = 0
  41.  
  42. try:
  43. with open(input_file, "r", encoding="utf-8", errors="ignore") as f_in, \
  44. open(output_file, "w", encoding="utf-8") as f_out:
  45.  
  46. for line in f_in:
  47. processed += 1
  48.  
  49. if ":" not in line:
  50. continue
  51.  
  52. line = line.strip()
  53. url_part, rest = line.split(":", 1)
  54.  
  55. if regex.search(url_part):
  56. if rest not in seen:
  57. seen.add(rest)
  58. f_out.write(rest + "\n")
  59. written += 1
  60.  
  61. if processed % 100000 == 0:
  62. status_label.config(
  63. text=f"Verwerkt: {processed:,} | Uniek: {written:,}"
  64. )
  65.  
  66. status_label.config(
  67. text=f"Klaar ✅ Verwerkt: {processed:,} | Uniek: {written:,}"
  68. )
  69.  
  70. except Exception as e:
  71. messagebox.showerror("Error", str(e))
  72.  
  73. start_button.config(state=tk.NORMAL)
  74.  
  75. threading.Thread(target=task, daemon=True).start()
  76.  
  77. # ---------------- GUI ----------------
  78.  
  79. root = tk.Tk()
  80. root.title("ULP Extractor (Regex + Dedup)")
  81. root.geometry("520x260")
  82. root.resizable(False, False)
  83.  
  84. tk.Label(root, text="Regex / Domein:").pack(anchor="w", padx=10, pady=(10, 0))
  85. regex_entry = tk.Entry(root, width=70)
  86. regex_entry.pack(padx=10)
  87.  
  88. tk.Label(root, text="Input ULP bestand:").pack(anchor="w", padx=10, pady=(10, 0))
  89. input_frame = tk.Frame(root)
  90. input_frame.pack(padx=10, fill="x")
  91. input_entry = tk.Entry(input_frame, width=55)
  92. input_entry.pack(side="left")
  93. tk.Button(input_frame, text="Browse", command=browse_input).pack(side="right")
  94.  
  95. tk.Label(root, text="Output bestand:").pack(anchor="w", padx=10, pady=(10, 0))
  96. output_frame = tk.Frame(root)
  97. output_frame.pack(padx=10, fill="x")
  98. output_entry = tk.Entry(output_frame, width=55)
  99. output_entry.pack(side="left")
  100. tk.Button(output_frame, text="Browse", command=browse_output).pack(side="right")
  101.  
  102. start_button = tk.Button(root, text="Start Extractie", command=run_extractor)
  103. start_button.pack(pady=15)
  104.  
  105. status_label = tk.Label(root, text="Wachten...")
  106. status_label.pack()
  107.  
  108. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment