Skip to content

Commit e753643

Browse files
committed
Remove onlineFetch
Removes onlineFetch. Adds a new function to initiate the download of images from the internet. Fixes NITDgpOS#303
1 parent 02f14f5 commit e753643

File tree

5 files changed

+31
-44
lines changed

5 files changed

+31
-44
lines changed

uiplib/gui/mainGui.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
from tkinter import *
66
from tkinter.ttk import *
77
from tkinter import messagebox
8+
from threading import Thread, active_count
9+
from shutil import copy
810

911
from uiplib.gui import generalTab, settingsTab
1012
from uiplib.scheduler import scheduler
1113
from uiplib.utils.utils import flush_wallpapers
12-
from shutil import copy
1314
from uiplib.settings import DEFAULT_FAVOURITE_PICS_FOLDER
15+
from uiplib.scrape import download
1416

1517

1618
class MainWindow:
@@ -98,6 +100,14 @@ def flush(self):
98100
icon='warning')
99101
if ask == 'yes':
100102
flush_wallpapers(self.settings['pics-folder'])
103+
if active_count() < 2:
104+
download_thread = Thread(
105+
target=download,
106+
args=(self.settings['website'],
107+
self.settings['pics-folder'],
108+
self.settings['no-of-images']),
109+
daemon=True)
110+
download_thread.start()
101111
self.update_images()
102112
else:
103113
print("Not Flushing!")

uiplib/scheduler.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
import random
88

99
from uiplib.utils.utils import get_percentage
10-
from uiplib.scrape.onlineFetch import onlineFetch
11-
from uiplib.scrape.scrape import get_images
10+
from uiplib.scrape import download
1211

1312
try:
1413
import msvcrt
1514
except ImportError:
1615
# not on windows
1716
pass
18-
from threading import Thread
17+
from threading import Thread, active_count
1918

2019

2120
class scheduler(Thread):
@@ -90,26 +89,13 @@ def deltaTime(self):
9089

9190
def run(self):
9291
"""Begin Scheduling Wallpapers."""
93-
if not self.offline:
94-
try:
95-
thread_nos = len(self.website)
96-
for i in range(thread_nos):
97-
# Init the thread
98-
fetch_thread = onlineFetch(self.website[i],
99-
self.directory, self.count)
100-
# die upon main thread exit
101-
fetch_thread.setDaemon(True)
102-
103-
# Start new Threads
104-
fetch_thread.start()
105-
106-
except ValueError as e:
107-
print("File could not be retrieved.", e)
108-
109-
while not ((os.path.isdir(self.directory) and
110-
os.listdir(self.directory) != [])):
111-
print('Downloading images..')
112-
time.sleep(60)
92+
if not self.offline and active_count() < 2:
93+
self.download_thread = Thread(
94+
target=download,
95+
args=(self.website, self.directory, self.count),
96+
daemon=True)
97+
self.download_thread.start()
98+
11399
elif not os.path.exists(self.directory):
114100
os.makedirs(self.directory)
115101

uiplib/scrape/scrape.py renamed to uiplib/scrape.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,14 @@ def get_images(url, directory, count):
157157
image_links = get_image_links(url, no_of_images)
158158
for image in image_links:
159159
download_store_images(os.path.join(directory, image[0]), image[1])
160+
161+
162+
def download(website, directory, count):
163+
"""Download images from the Internet."""
164+
print('Downloading images..')
165+
try:
166+
for site in website:
167+
get_images(site, directory, count)
168+
169+
except ValueError as e:
170+
print("File could not be retrieved.", e)

uiplib/scrape/__init__.py

Whitespace-only changes.

uiplib/scrape/onlineFetch.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)