From 4f2e9bcb4b46469aa53f1bc0a4fe056e4be00cbe Mon Sep 17 00:00:00 2001 From: angoosh Date: Tue, 15 Jul 2025 00:36:55 +0200 Subject: [PATCH] added site edit script and img folder with mandatory file in it --- edit.py | 126 ++++++++++++++++++++++++++++++++++++++++++++++++ home.html | 19 ++++++-- img/unknown.png | Bin 0 -> 1449671 bytes 3 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 edit.py create mode 100644 img/unknown.png diff --git a/edit.py b/edit.py new file mode 100644 index 0000000..ca26650 --- /dev/null +++ b/edit.py @@ -0,0 +1,126 @@ +import tkinter as tk +from tkinter import messagebox +from tkinter import filedialog +import os +import shutil + +HTML_INSERT_TAG = "" +uploaded_image_path = None # Global to track uploaded image + +def upload_image(): + global uploaded_image_path + path = filedialog.askopenfilename( + title="Select an Image", + filetypes=[("Image Files", "*.png;*.jpg;*.jpeg;*.gif;*.mp4"), ("All Files", "*.*")] + ) + if path: + uploaded_image_path = path + messagebox.showinfo("Image Uploaded", f"Selected image:\n{os.path.basename(path)}") + + +def submit_content(): + global uploaded_image_path + + date = date_text.get("1.0", tk.END).strip() + title = title_text.get("1.0", tk.END).strip() + content = content_text.get("1.0", tk.END).strip() + img_lib = img_lib_text.get("1.0", tk.END).strip() + + if not date or not title or not content: + messagebox.showerror("Error", "All fields must be filled out.") + return + +# html_file_path = filedialog.askopenfilename( +# title="Select HTML File", +# filetypes=[("HTML files", "*.html"), ("All files", "*.*")] +# ) + +# if not html_file_path: +# return + html_file_path = './home.html' + + if not img_lib: + new_entry = f""" +
  • {date}
  • +
  • {title}
  • +
  • {content}
  • + """ + else: + new_entry = f""" +
  • {date}
  • +
  • {title}
  • +
  • {content}
  • +
  • Odkaz na foto galerii
  • + """ + + image_tag = "" + if uploaded_image_path: + try: + html_dir = os.path.dirname(html_file_path) + img_name = os.path.basename(uploaded_image_path) + target_path = os.path.join(html_dir, img_name) + target_path = "img/"+target_path[2:] + print(target_path) + + # Copy image to HTML file directory + shutil.copy(uploaded_image_path, target_path) + if '.mp4' in target_path: + image_tag = f'
  • ' + else: + image_tag = f'
  • Image
  • ' + except Exception as e: + messagebox.showwarning("Image Error", f"Could not copy image: {str(e)}") + + + try: + if not os.path.exists(html_file_path): + with open(html_file_path, 'w') as f: + f.write(f"\n{HTML_INSERT_TAG}\n") + + with open(html_file_path, 'r', encoding='utf-8') as f: + html_content = f.read() + + if HTML_INSERT_TAG not in html_content: + messagebox.showerror("Error", f"Insert tag '{HTML_INSERT_TAG}' not found in HTML file.") + return + + full_entry = f"{new_entry}\n{image_tag}" if image_tag else new_entry + new_html = html_content.replace(HTML_INSERT_TAG, f"{HTML_INSERT_TAG}\n{full_entry}") + + with open(html_file_path, 'w', encoding='utf-8') as f: + f.write(new_html) + + messagebox.showinfo("Success", "Content inserted into HTML file.") + except Exception as e: + messagebox.showerror("Error", str(e)) + + +# GUI Setup +root = tk.Tk() +root.title("HTML Content Inserter") +root.geometry("400x550") + +tk.Label(root, text="Date:").pack(anchor='w', padx=10) +date_text = tk.Text(root, height=2, width=40) +date_text.pack(padx=10, pady=5) + +tk.Label(root, text="Title:").pack(anchor='w', padx=10) +title_text = tk.Text(root, height=2, width=40) +title_text.pack(padx=10, pady=5) + +tk.Label(root, text="Content:").pack(anchor='w', padx=10) +content_text = tk.Text(root, height=10, width=40) +content_text.pack(padx=10, pady=5) + +upload_button = tk.Button(root, text="Upload Image/Video", command=upload_image) +upload_button.pack(pady=5) + +tk.Label(root, text="Link to image library:").pack(anchor='w', padx=10) +img_lib_text = tk.Text(root, height=2, width=40) +img_lib_text.pack(padx=10, pady=5) + +submit_button = tk.Button(root, text="Submit to HTML", command=submit_content) +submit_button.pack(pady=5) + +root.mainloop() + diff --git a/home.html b/home.html index c615d7b..e6b080c 100644 --- a/home.html +++ b/home.html @@ -7,29 +7,38 @@
    -

    Welcome to FMCZ

    +

    Vítejte na stránkách FMCZ

    -

    About Us

    +

    O nás

    Welcome to FMCZ. We are a forward-thinking organization dedicated to excellence in our domain.

    News Feed