Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import filedialog, messagebox
- import re
- import threading
- def browse_input():
- path = filedialog.askopenfilename(filetypes=[("ULP files", "*.ulp"), ("All files", "*.*")])
- if path:
- input_entry.delete(0, tk.END)
- input_entry.insert(0, path)
- def browse_output():
- path = filedialog.asksaveasfilename(defaultextension=".txt",
- filetypes=[("Text files", "*.txt")])
- if path:
- output_entry.delete(0, tk.END)
- output_entry.insert(0, path)
- def run_extractor():
- input_file = input_entry.get().strip()
- output_file = output_entry.get().strip()
- pattern = regex_entry.get().strip()
- if not input_file or not output_file or not pattern:
- messagebox.showerror("Fout", "Vul alles in.")
- return
- try:
- regex = re.compile(pattern, re.IGNORECASE)
- except re.error:
- messagebox.showerror("Fout", "Ongeldige regex.")
- return
- start_button.config(state=tk.DISABLED)
- status_label.config(text="Bezig...")
- def task():
- seen = set()
- processed = 0
- written = 0
- try:
- with open(input_file, "r", encoding="utf-8", errors="ignore") as f_in, \
- open(output_file, "w", encoding="utf-8") as f_out:
- for line in f_in:
- processed += 1
- if ":" not in line:
- continue
- line = line.strip()
- url_part, rest = line.split(":", 1)
- if regex.search(url_part):
- if rest not in seen:
- seen.add(rest)
- f_out.write(rest + "\n")
- written += 1
- if processed % 100000 == 0:
- status_label.config(
- text=f"Verwerkt: {processed:,} | Uniek: {written:,}"
- )
- status_label.config(
- text=f"Klaar ✅ Verwerkt: {processed:,} | Uniek: {written:,}"
- )
- except Exception as e:
- messagebox.showerror("Error", str(e))
- start_button.config(state=tk.NORMAL)
- threading.Thread(target=task, daemon=True).start()
- # ---------------- GUI ----------------
- root = tk.Tk()
- root.title("ULP Extractor (Regex + Dedup)")
- root.geometry("520x260")
- root.resizable(False, False)
- tk.Label(root, text="Regex / Domein:").pack(anchor="w", padx=10, pady=(10, 0))
- regex_entry = tk.Entry(root, width=70)
- regex_entry.pack(padx=10)
- tk.Label(root, text="Input ULP bestand:").pack(anchor="w", padx=10, pady=(10, 0))
- input_frame = tk.Frame(root)
- input_frame.pack(padx=10, fill="x")
- input_entry = tk.Entry(input_frame, width=55)
- input_entry.pack(side="left")
- tk.Button(input_frame, text="Browse", command=browse_input).pack(side="right")
- tk.Label(root, text="Output bestand:").pack(anchor="w", padx=10, pady=(10, 0))
- output_frame = tk.Frame(root)
- output_frame.pack(padx=10, fill="x")
- output_entry = tk.Entry(output_frame, width=55)
- output_entry.pack(side="left")
- tk.Button(output_frame, text="Browse", command=browse_output).pack(side="right")
- start_button = tk.Button(root, text="Start Extractie", command=run_extractor)
- start_button.pack(pady=15)
- status_label = tk.Label(root, text="Wachten...")
- status_label.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment