-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckpointFinder.py
More file actions
84 lines (69 loc) · 2.88 KB
/
CheckpointFinder.py
File metadata and controls
84 lines (69 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#How To Use
#Enter your username (partial or full) and select a ZIP file to search for related lines of text.
import os
import re
import zipfile
import tempfile
import tkinter as tk
from tkinter import filedialog, scrolledtext, simpledialog
# Regular expression to capture the author and text from the JSON content
pattern = r'"author": "(?P<author>.*?)",.*?"text": "(?P<text>.*?)"'
def extract_and_search(zip_path, username):
# Initialize a dictionary to store the related lines
related_lines_local = {}
# Create a temporary directory to extract the ZIP contents
with tempfile.TemporaryDirectory() as tmpdirname:
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(tmpdirname)
# Iterate through each file in the temporary directory
for file_name in os.listdir(tmpdirname):
file_path = os.path.join(tmpdirname, file_name)
# Open the file and read its content
with open(file_path, 'r', errors='replace') as file:
content = file.read()
matches = re.findall(pattern, content)
for match in matches:
author, text = match
if username in author:
if file_name not in related_lines_local:
related_lines_local[file_name] = []
related_lines_local[file_name].append(f"{author} - {text}")
# Filter for unique lines and return the results
output = []
for file, lines in related_lines_local.items():
unique_lines = list(set(lines))
sorted_unique_lines = sorted(unique_lines)
output.append(f"In file {file}:")
output.extend(iter(sorted_unique_lines))
output.append("\n")
return "\n".join(output)
def select_zip_file():
# Ask the user for the username
username = simpledialog.askstring("Input", "Please enter the username:")
if not username:
return
if file_path := filedialog.askopenfilename(
title="Select ZIP File", filetypes=[("ZIP files", "*.zip")]
):
results = extract_and_search(file_path, username)
# Display the results in the text box
text_box.delete(1.0, tk.END)
text_box.insert(tk.END, results)
# Create the main GUI window
root = tk.Tk()
root.title("ZIP Search Tool")
root.geometry("600x400")
# Dark mode colors
bg_color = '#2E2E2E'
fg_color = '#FFFFFF'
btn_color = '#424242'
text_box_color = '#424242'
# Apply dark mode colors
root.configure(bg=bg_color)
# Add a button to select the ZIP file
btn = tk.Button(root, text="Select Username and ZIP File", command=select_zip_file, bg=btn_color, fg=fg_color)
btn.pack(pady=20)
# Add a scrolled text box to display the results
text_box = scrolledtext.ScrolledText(root, wrap=tk.WORD, width=70, height=15, bg=text_box_color, fg=fg_color, insertbackground=fg_color)
text_box.pack(pady=20)
root.mainloop()