Repository navigation
Expand file tree
/
Copy pathEdit.py
More file actions
67 lines (49 loc) · 2.1 KB
/
Copy pathEdit.py
File metadata and controls
67 lines (49 loc) · 2.1 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
######### NOT DEBUGGED PLEASE LEAVE FOR NOW
//imported pandas and tkinter
def copy_and_rename_files(product):
folder_path = os.path.dirname(os.path.realpath(__file__))
original_file = os.path.join(folder_path, "output_file.csv")
product_file = os.path.join(folder_path, f"{product}_output.csv")
link_output_file = os.path.join(folder_path, "Link_Output.csv")
renamed_link_output_file = os.path.join(folder_path, f"{product}_Link_Output.csv")
# Initialize tkinter elements (for logging)
root = tk.Tk()
root.withdraw() # Hide the root window
log_text = tk.Text(root)
log_text.pack()
def log_message(message):
log_text.insert(tk.END, message + '\n')
root.update_idletasks()
# Copy and rename the original file
try:
df = pd.read_csv(original_file)
df.to_csv(product_file, index=False)
log_message(f"Copied and renamed to {product_file}.")
except FileNotFoundError:
log_message(f"Error: {original_file} does not exist.")
# Copy and rename the Link_Output file
try:
df_link = pd.read_csv(link_output_file)
df_link.to_csv(renamed_link_output_file, index=False)
log_message(f"Copied and renamed to {renamed_link_output_file}.")
except FileNotFoundError:
log_message(f"Error: {link_output_file} does not exist.")
def filter_and_append_to_csv(input_file, output_file, product):
# Read the input CSV file
df = pd.read_csv(input_file)
# Filter the DataFrame based on the product name
filtered_df = df[df['Product'].str.contains(product, na=False)]
# Append to the output CSV file
filtered_df.to_csv(output_file, mode='a', index=False, header=not pd.read_csv(output_file).empty)
log_text.insert(tk.END, f"Filtered and appended data to {output_file}.\n")
root.update_idletasks()
# Example of initializing tkinter elements
root = tk.Tk()
log_text = tk.Text(root)
log_text.pack()
# Example usage
filter_and_append_to_csv('input.csv', 'output.csv', 'ProductA')
root.mainloop()
root.mainloop()
# Example usage
copy_and_rename_files('example_product')