-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
39 lines (27 loc) · 1.05 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import multiprocessing
__author__ = 'karunab'
from resolution import Resolution
from download import Downloadable, perform_download
from display import get_resolution
from desktoppr import Desktoppr
def add_to_downloads_queue():
is_first = True
while desktoppr.has_next() and (is_first or not desktoppr.should_break()):
is_first = False
print "Fetching page %d" % desktoppr.get_next_page_no()
for wallpaper in desktoppr.next(screen):
downloads.append(Downloadable.from_wallpaper(base_path_on_disk, wallpaper))
def process_downloads():
pool = multiprocessing.Pool(processes=5) # use 5 processes to download the data
return pool.map(perform_download, downloads)
## Main code
screen = Resolution.from_tuple(get_resolution())
print "Screen details: %s\n" % screen
start_page = 1
page_break_at = 5
desktoppr = Desktoppr(start_page, page_break_at)
downloads = list()
base_path_on_disk = '/Users/karunab/Pictures/Wallpapers/%s' % screen
while desktoppr.has_next():
add_to_downloads_queue()
process_downloads()