Skip to content

Commit

Permalink
Merge pull request #38 from Jaime-alv/upgrade_file_paths
Browse files Browse the repository at this point in the history
Upgrade file paths
  • Loading branch information
Jaime-alv committed Nov 9, 2021
2 parents 0bed069 + facede3 commit dac6281
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dist/
# other files
MANIFEST.in
pyproject.toml
image/logo.png
image/logo.psd
image/icon.psd
image/icon_bw.psd
image/logo_new.png
Binary file modified image/icon_bw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
requests~=2.26.0
beautifulsoup4~=4.10.0
tkScrolledFrame~=1.0.4
setuptools~=57.4.0
Pillow~=8.3.2
setuptools~=57.4.0
2 changes: 1 addition & 1 deletion web_check/add_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def create_folder(root):

if __name__ == "__main__":
try:
logging.basicConfig(filename='../storage/logs/log.txt', level=logging.DEBUG,
logging.basicConfig(filename=pathlib.Path('../storage/logs/log.txt'), level=logging.DEBUG,
format='%(levelname)s - %(message)s')
with pathlib.Path(f'../storage/url_list.txt').open('r') as json_file:
stored_url = json.load(json_file)
Expand Down
8 changes: 4 additions & 4 deletions web_check/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, root, stored_url):
self.css_selector = self.list_of_saved_url[each_url]['css_selector']
self.charset = self.list_of_saved_url[each_url]['encoding']
self.url = each_url
self.path = f'{self.root}\\url_data\\{self.file_name}.txt'
self.path = pathlib.Path(f'{self.root}\\url_data\\{self.file_name}.txt')
logging.info(f'url = {self.url}')
logging.info(f'file_name = {self.file_name}')
logging.info(f'selector = {self.css_selector}')
Expand All @@ -65,7 +65,7 @@ def compare_url(self):
temp_file.write(chunk)
temp_file.close()

compare_files = filecmp.cmp(f'{self.root}\\url_data\\temp.txt', self.path, shallow=False)
compare_files = filecmp.cmp(pathlib.Path(f'{self.root}\\url_data\\temp.txt'), self.path, shallow=False)
if compare_files:
logging.warning(f"{self.url} Equal to stored one")
elif not compare_files:
Expand All @@ -89,7 +89,7 @@ def prompt_differences(self):
# update stored file with new text and create backup with old text
def save_url(self):
logging.warning(f'Updating file with {self.url} in {self.path}')
shutil.move(self.path, f'{self.root}\\url_data\\backup\\{self.file_name}_backup.txt')
shutil.move(self.path, pathlib.Path(f'{self.root}\\url_data\\backup\\{self.file_name}_backup.txt'))
backup = pathlib.Path(f'{self.root}\\url_data\\backup\\{self.file_name}_backup.txt').open('r')
backup.close()

Expand All @@ -112,7 +112,7 @@ def save_url(self):
if __name__ == "__main__":
directory = '..\\storage'
try:
logging.basicConfig(filename=f'{directory}\\logs\\log.txt', level=logging.DEBUG,
logging.basicConfig(filename=pathlib.Path(f'{directory}\\logs\\log.txt'), level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s')
pathlib.Path('../storage/logs/log.txt').open('w')
with pathlib.Path(f'{directory}\\url_list.txt').open('r') as file:
Expand Down
96 changes: 45 additions & 51 deletions web_check/main.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,33 @@ import tkinter
from tkinter import ttk
from tkinter import messagebox
from tkinter import filedialog
from PIL import ImageTk, Image
from checker import CompareUrl
from add_url import *
from tkscrolledframe import ScrolledFrame


class WebCheckGUI(tkinter.Frame):
def __init__(self, master, root):
super().__init__(master)
class WebCheckGUI(tkinter.Tk):
def __init__(self, root):
super().__init__()
self.root = root
with pathlib.Path(f'{self.root}\\url_list.txt').open('r') as file:
self.list_of_saved_url = json.load(file)
style = tkinter.ttk.Style()
style.configure('TNotebook.Tab', font=('bahnschrift', 13))
style.configure('TNotebook', font=('bahnschrift', 10))
self.master = master
self.master.geometry('650x480')
self.pack(expand=1, fill='both')
self.master.title('web check')
icon_file = pathlib.Path('../image/icon_bw.png')
background_image = pathlib.Path('../image/logo.png')
self.icon = tkinter.PhotoImage(file=icon_file)
self.logo = tkinter.PhotoImage(file=background_image)
self.master_frame = tkinter.Frame(self)
self.wm_iconphoto(False, self.icon)
self.title('web check')
self.master_frame.pack(expand=1, fill='both')
self.minsize(width=400, height=480)
self.for_delete = []

# create the different tabs in the script
self.tab_control = tkinter.ttk.Notebook(self)
self.tab_control = tkinter.ttk.Notebook(self.master_frame)
self.tab_home = ttk.Frame(self.tab_control)
self.tab_add_url = ttk.Frame(self.tab_control)
self.tab_modify_url = ttk.Frame(self.tab_control)
Expand All @@ -51,6 +56,7 @@ class WebCheckGUI(tkinter.Frame):
self.tab_control.add(self.tab_modify_url, text='Modify url')
self.tab_control.add(self.tab_delete_url, text='Delete url')
self.tab_control.pack(expand=1, fill='both')

self.main()

# create everything
Expand All @@ -65,25 +71,20 @@ class WebCheckGUI(tkinter.Frame):
self.create_menu()

def terminate(self):
close_program = tkinter.Button(self, fg='red', command=self.master.destroy, font=('bahnschrift', 11))
close_program['text'] = 'Close script'
close_program['padx'] = 5
close_program['pady'] = 5
close_program.pack(side='bottom', anchor='e')
close_program = tkinter.Button(self.master_frame, fg='red', text='Close', command=self.destroy,
font=('bahnschrift', 11))
close_program.pack(side='bottom', anchor='e', padx=3, pady=3)

# create home tab
def home(self):
image = Image.open('../image/logo_new.png')
image = image.resize((350, 200), Image.ANTIALIAS)
img = ImageTk.PhotoImage(image)
panel = tkinter.Label(self.tab_home, image=img)
panel.image = img
panel = tkinter.Label(self.tab_home, image=self.logo)
panel.image = self.logo
panel.pack(pady=20)

button_run_script = tkinter.Button(self.tab_home, text='Run!')
button_run_script = tkinter.Button(self.tab_home, text='Run!', width=6)
button_run_script['command'] = self.run_script
button_run_script['font'] = ('bahnschrift', 15, 'bold')
button_run_script.pack(side='top', anchor='center', expand=1, ipadx=20, ipady=5)
button_run_script.pack(side='top', anchor='center', expand=1)
label_copyright = tkinter.Label(self.tab_home, font=('bahnschrift', 10), fg='#686565')
label_copyright['text'] = 'Copyright (C) 2021 Jaime Álvarez Fernández'
label_copyright.pack(side='bottom', anchor='s')
Expand Down Expand Up @@ -118,7 +119,7 @@ class WebCheckGUI(tkinter.Frame):
line_by_line = self.whats_new_file.open('r', encoding='utf-8').readlines()
whats_new_window = tkinter.Toplevel(self)
whats_new_window.title("What's new today?")
whats_new_window.wm_iconphoto(False, icon)
whats_new_window.wm_iconphoto(False, self.icon)

scroll_whats_new = ScrolledFrame(whats_new_window, width=450, height=250)
scroll_whats_new.pack(side="top", expand=1, fill="both")
Expand Down Expand Up @@ -158,8 +159,8 @@ class WebCheckGUI(tkinter.Frame):
batch_button.pack(anchor='nw', expand=1, pady=20, padx=10)
batch_button['command'] = self.add_batch_url

submit_button = tkinter.Button(self.tab_add_url, text='Submit new url', font=('bahnschrift', 11))
submit_button.pack(anchor='center', expand=1, ipadx=50, ipady=5)
submit_button = tkinter.Button(self.tab_add_url, text='Submit new url', font=('bahnschrift', 11), width=14)
submit_button.pack(anchor='s', expand=1, ipady=2, pady=3)
submit_button['command'] = self.add_new_url

def add_batch_url(self):
Expand Down Expand Up @@ -218,8 +219,8 @@ class WebCheckGUI(tkinter.Frame):
self.scroll_frame_mod_url.bind_scroll_wheel(self.tab_modify_url)
self.modify_frame = self.scroll_frame_mod_url.display_widget(tkinter.Frame)

button_submit = tkinter.Button(self.tab_modify_url, text='Submit', font=('bahnschrift', 11))
button_submit.pack(side='bottom', anchor='s', ipadx=31, ipady=5)
button_submit = tkinter.Button(self.tab_modify_url, text='Submit', font=('bahnschrift', 11), width=10)
button_submit.pack(side='bottom', anchor='s', ipady=3, pady=2)
button_submit['command'] = self.modify_this_url

def create_radio_button(self):
Expand Down Expand Up @@ -255,11 +256,11 @@ class WebCheckGUI(tkinter.Frame):

frame_delete_button = tkinter.Frame(self.tab_delete_url)
frame_delete_button.pack(side='bottom')
submit_button = tkinter.Button(frame_delete_button, text='Delete', font=('bahnschrift', 11))
submit_button.grid(row=0, column=1, ipadx=50, ipady=5)
submit_button = tkinter.Button(frame_delete_button, text='Delete', font=('bahnschrift', 11), width=10)
submit_button.grid(row=0, column=1, ipady=2, pady=3, padx=1)
submit_button['command'] = self.delete_only
submit_button = tkinter.Button(frame_delete_button, text='Delete all', font=('bahnschrift', 11))
submit_button.grid(row=0, column=0, ipadx=43, ipady=5)
submit_button = tkinter.Button(frame_delete_button, text='Delete all', font=('bahnschrift', 11), width=10)
submit_button.grid(row=0, column=0, ipady=2, pady=3, padx=1)
submit_button['command'] = self.delete_all

def create_check_button(self):
Expand Down Expand Up @@ -295,7 +296,7 @@ class WebCheckGUI(tkinter.Frame):
self.for_delete.remove(order[i])

def create_menu(self):
menu = tkinter.Menu(self.master)
menu = tkinter.Menu(self)

new_item = tkinter.Menu(menu, tearoff=0)
new_item.add_command(label='Reset url file', command=self.reset_url_file)
Expand All @@ -304,10 +305,10 @@ class WebCheckGUI(tkinter.Frame):
new_item.add_separator()
new_item.add_command(label='About', command=self.about_script)
new_item.add_separator()
new_item.add_command(label='Close', command=self.master.destroy)
new_item.add_command(label='Close', command=self.destroy)

menu.add_cascade(label='Options', menu=new_item)
self.master.config(menu=menu)
self.config(menu=menu)

# re-write url_list.txt completely empty
def reset_url_file(self):
Expand Down Expand Up @@ -360,16 +361,17 @@ class WebCheckGUI(tkinter.Frame):

# create a new window with all info about the script
def about_script(self):
new_window = tkinter.Toplevel(self)
new_window = tkinter.Toplevel()
new_window.title('About...')
new_window.geometry('450x200')
new_window.resizable(False, False)
new_window.wm_iconphoto(False, icon)
new_window.wm_iconphoto(False, self.icon)
new_window.focus()
font = ('bahnschrift', 10)
script = 'Web check'
contact = 'Contact: [email protected]'
repository = 'Repository: https://github.com/Jaime-alv/web_check.git'
version = 'Version: v1.1.0'
version = 'Version: v1.2.0'
license_script = 'License: GPL-3.0-or-later'
author = 'Author: Jaime Álvarez Fernández'

Expand All @@ -383,10 +385,8 @@ class WebCheckGUI(tkinter.Frame):
left_frame = tkinter.Frame(middle_frame)
left_frame.pack(side='left')

image = ico.resize((80, 80), Image.ANTIALIAS)
img = ImageTk.PhotoImage(image)
panel = tkinter.Label(left_frame, image=img)
panel.image = img
panel = tkinter.Label(left_frame, image=self.icon)
panel.image = self.icon
panel.pack(padx=10)

contact_label = tkinter.Label(right_frame, text=contact, font=font)
Expand All @@ -400,23 +400,17 @@ class WebCheckGUI(tkinter.Frame):
author_label = tkinter.Label(right_frame, text=author, font=font)
author_label.pack(anchor='w', padx=10, pady=2)

close_window = tkinter.Button(new_window, text='Ok', font=('bahnschrift', 12), command=new_window.destroy)
close_window.pack(pady=4, anchor='s', side='bottom', ipadx=33)
close_window = tkinter.Button(new_window, text='Ok', font=('bahnschrift', 12), width=6, fg='red',
command=new_window.destroy)
close_window.pack(pady=4, anchor='s', side='bottom')


if __name__ == "__main__":
directory = '..\\storage'
try:
logging.basicConfig(filename=f'{directory}\\logs\\log.txt', level=logging.DEBUG,
logging.basicConfig(filename=pathlib.Path(f'{directory}\\logs\\log.txt'), level=logging.DEBUG,
format='%(asctime)s - %(levelname)s - %(message)s')
pathlib.Path(f'{directory}\\logs\\log.txt').open('w')
except FileNotFoundError:
create_folder(directory)
pil_logger = logging.getLogger('PIL')
pil_logger.setLevel(logging.INFO)
window = tkinter.Tk()
app = WebCheckGUI(window, directory)
ico = Image.open('../image/icon_bw.png')
icon = ImageTk.PhotoImage(ico)
window.wm_iconphoto(False, icon)
app.mainloop()
WebCheckGUI(directory).mainloop()

0 comments on commit dac6281

Please sign in to comment.