Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d0a4f76

Browse files
committed
Add progress bar GUI to script
This can be improved, but it's fully functional as it is now
1 parent 42fd92e commit d0a4f76

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

‎Reddit Meme Scraper/script.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,39 @@ def read_secret(self):
6464
image_timestamps.append(dt.datetime.fromtimestamp(post.created))
6565
image_ids.append(post.id)
6666

67+
# This creates a GUI window with a progress bar to keep track of the download
68+
69+
layout = [[sg.Text(f"Downloading files...", key='textkey')],
70+
[sg.ProgressBar(25, orientation='h', size=(20, 20), key='progbar')],
71+
[sg.Cancel()]]
72+
73+
window = sg.Window('Download in Progress', layout)
74+
6775
# This iterates through URLs, checks if it has the specified image extension and downloads the image
6876

6977
for index, url in enumerate(image_urls):
7078
path = str(folder_lst[0])
7179
file_ending = str(url)[2:-1]
80+
event, values = window.read(timeout=0)
7281
_, extension = os.path.splitext(file_ending)
7382
if extension in image_extensions:
7483
try:
7584
if os.path.exists(path + '/' + 'Downloaded Images'):
7685
pass
7786
else:
7887
os.mkdir(path + '/' + 'Downloaded Images')
88+
if event == 'Cancel' or event == sg.WIN_CLOSED:
89+
break
7990

8091
destination = str(folder_lst[0]) + '/' + 'Downloaded Images' + '/'
92+
window['progbar'].update_bar(index + 1)
8193
print(f"Downloading '{str(image_titles[index])[2:-1]}' to '{path}' from '{str(image_urls[index])[2:-1]}'")
8294
download = wget.download(str(image_urls[index])[2:-1], out=destination)
8395
except:
8496
print(f"Something went wrong while downloading '{str(image_urls[index])[2:-1]}'\n")
8597
else:
8698
print("\nDownload complete!")
99+
window.close()
87100
sg.Popup(f"Files downloaded into:\n\n'{path}/Downloaded Images'", title='Download complete!')
88101

89102

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /