From f1a3f7101c0ea7eca9a85123bed30ec093dc0c51 Mon Sep 17 00:00:00 2001 From: Joost Agterhoek Date: Thu, 15 Aug 2024 21:22:21 +0200 Subject: [PATCH] autoformat --- tkinter-enter.py | 80 +++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/tkinter-enter.py b/tkinter-enter.py index e632782..4a9f24d 100644 --- a/tkinter-enter.py +++ b/tkinter-enter.py @@ -3,7 +3,15 @@ # importing tkinter import tkinter as tk -from generic import sanitize, type_hosts_listed, type_hosts_organized, ip_lookup, domain_lookup, spf_dmarc +from generic import ( + sanitize, + type_hosts_listed, + type_hosts_organized, + ip_lookup, + domain_lookup, + spf_dmarc, +) + # function to run on pressing # 'ENTER' key from keyboard. @@ -12,46 +20,47 @@ def key_handler_function(event): print(type(inputs)) sanitized = sanitize.strip_and_list(inputs) typed = type_hosts_listed.type_hosts(sanitized) - textbox.insert('end', typed) + textbox.insert("end", typed) listed = type_hosts_organized.type_hosts(sanitized) # IPs = listed['IPs'] # below works for updating a global variable (here)... - var.set(listed['IPs']) - ip_listbox.delete(0, 'end') - domain_listbox.delete(0, 'end') - url_listbox.delete(0, 'end') - email_listbox.delete(0, 'end') + var.set(listed["IPs"]) + ip_listbox.delete(0, "end") + domain_listbox.delete(0, "end") + url_listbox.delete(0, "end") + email_listbox.delete(0, "end") - for IP in listed['IPs']: + for IP in listed["IPs"]: hostname = ip_lookup.get_hostname(IP) output = "{} => {}".format(IP, hostname[0]) - ip_listbox.insert('end', output) - for domain in listed['domains']: + ip_listbox.insert("end", output) + for domain in listed["domains"]: ip = domain_lookup.get_ip_address(domain) output = "{} => {}".format(domain, ip) - domain_listbox.insert('end', output) - for URL in listed['URLs']: - url_listbox.insert('end', URL) - for email in listed['emails']: + domain_listbox.insert("end", output) + for URL in listed["URLs"]: + url_listbox.insert("end", URL) + for email in listed["emails"]: dmarc, spf = spf_dmarc.lookup(email) output_dmarc = "{} => {}".format(email, dmarc) output_spf = "{} => {}".format(email, spf) - email_listbox.insert('end', output_dmarc, output_spf) + email_listbox.insert("end", output_dmarc, output_spf) def test_button_function(): # testing quoting and comma separating hosts, IPs for now, from global StringVar var - textbox.delete(1.0, 'end') - IPs = ', '.join([f'"{host}"' for host in var.get()]) - textbox.insert('end', IPs) + textbox.delete(1.0, "end") + IPs = ", ".join([f'"{host}"' for host in var.get()]) + textbox.insert("end", IPs) print("var is : {}".format(var.get())) # ... and printing an updated global variable here! + # main application window root = tk.Tk() root.title("Enter IP addresses, URLs, domains, email addresses") root.geometry("900x600") -root.resizable(0,0) +root.resizable(0, 0) # configure the grid root.columnconfigure(0, weight=1) @@ -59,7 +68,7 @@ root.columnconfigure(1, weight=1) root.columnconfigure(2, weight=1) root.columnconfigure(3, weight=1) -#Listing stuff +# Listing stuff # creating widgets entry = tk.Entry(root, text="Put in IP addresses, URLs, domains, email addresses") @@ -72,29 +81,30 @@ domain_label = tk.Label(root, text="domain => IP") domain_listbox = tk.Listbox(root) url_label = tk.Label(root, text="URL => IP") url_listbox = tk.Listbox(root) -email_label = tk.Label(root, text="email address => DMARC/SPF") +email_label = tk.Label(root, text="email address => DMARC/SPF") email_listbox = tk.Listbox(root) -var = tk.Variable() -entrylabel.grid(column=1, row=0, columnspan=2, sticky='nsew') -entry.grid(column=0, row=1, columnspan=4, sticky='nsew') -ip_label.grid(column=0, row=2, columnspan=2, sticky='nsew') -ip_listbox.grid(column=0, row=3, columnspan=2, sticky='nsew') -domain_label.grid(column=2, row=2, columnspan=2, sticky='nsew') -domain_listbox.grid(column=2, row=3, columnspan=2, sticky='nsew') -url_label.grid(column=0, row=4, columnspan=2, sticky='nsew') -url_listbox.grid(column=0, row=5, columnspan=2, sticky='nsew') -email_label.grid(column=2, row=4, columnspan=2, sticky='nsew') -email_listbox.grid(column=2, row=5, columnspan=2, sticky='nsew') +var = tk.Variable() +entrylabel.grid(column=1, row=0, columnspan=2, sticky="nsew") +entry.grid(column=0, row=1, columnspan=4, sticky="nsew") +ip_label.grid(column=0, row=2, columnspan=2, sticky="nsew") +ip_listbox.grid(column=0, row=3, columnspan=2, sticky="nsew") +domain_label.grid(column=2, row=2, columnspan=2, sticky="nsew") +domain_listbox.grid(column=2, row=3, columnspan=2, sticky="nsew") +url_label.grid(column=0, row=4, columnspan=2, sticky="nsew") +url_listbox.grid(column=0, row=5, columnspan=2, sticky="nsew") +email_label.grid(column=2, row=4, columnspan=2, sticky="nsew") +email_listbox.grid(column=2, row=5, columnspan=2, sticky="nsew") # label.grid(column=1, row=2) # textbox.grid(column=1, row=3) -#Trying out buttons -test_button = tk.Button(root, text="comma-separate and add quotes", command=test_button_function) +# Trying out buttons +test_button = tk.Button( + root, text="comma-separate and add quotes", command=test_button_function +) # Binding ENTER key to function entry.bind("", key_handler_function) # run the application root.mainloop() -