-
Notifications
You must be signed in to change notification settings - Fork 8
/
QuickWall.py
99 lines (79 loc) · 3.55 KB
/
QuickWall.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python3
"""Uses unsplash API to set wallpapers from the cli."""
import requests
import argparse
from QuickWall.SetPaper import SetPaper
from QuickWall.utility import (
is_nitrogen,
clear_cache,
migrate_to_new_loc
)
from QuickWall.logger import Logger
from QuickWall.setter import WallSetter
from QuickWall.wall import Wall
from QuickWall.blacklist import Blacklist
# Declare the logger
logger = Logger("main")
def parse():
"""Parse the arguments."""
parser = argparse.ArgumentParser(description="QuickWall - Quickly set\
latest wallpapers from Unsplash\
directly from the commandline.",
epilog="If you find any bugs, feel\
free to raise an issue in the GitHub\
[https://github.com/deepjyoti30/QuickWall] page.")
parser.add_argument('--version', action='version', version='0.0.2',
help='show the program version number and exit')
parser.add_argument('--clear-cache', help="Clear the cache from the\
cache folder (~/.cache/QuickWall)", action='store_true')
parser.add_argument('--setter', help="Wallpaper setter to be used.\
Currently supported ones: nitrogen, feh (default: nitrogen)",
type=str, default=None)
parser.add_argument('-d', '--disable-blacklist', help="Disable adding the\
image to blacklisted ones.", action="store_true")
parser.add_argument('--remove-id', help="Remove the passed ID\
from the blacklist.", default=None, type=str, metavar="ID")
parser.add_argument('--dir', help="Directory to download the wallpapers",
type=str, default=None)
parser.add_argument('--id', help="Get a photo by its ID.",
type=str, default=None, metavar="ID")
parser.add_argument('--random', help="Get random wallpapers.",
action="store_true")
parser.add_argument('--search', help="Show wallpapers based on the\
passed term", type=str, metavar="TERM")
parser.add_argument('--migrate', help="ONLY FOR EARLY USERS. Move the files\
from ~/.QuickWall to ~/.cache/QuickWall.", action="store_true")
parser.add_argument('--set-lockscreen', help="Set lockscreen wallpaper (currently for KDE)",
action='store_true')
args = parser.parse_args()
return args
def main():
# Parse the arguments
args = parse()
if args.clear_cache:
clear_cache()
exit(0)
if args.migrate:
migrate_to_new_loc()
exit(0)
if args.remove_id:
blacklist = Blacklist(args.remove_id).remove_blacklist()
exit(0)
wall = Wall(photo_id=args.id, random=args.random, search=args.search)
# Get the wallpaper setter
if args.setter is None:
args.setter = WallSetter._detect_setter()
wall_setter = WallSetter(args.setter, args.set_lockscreen)
setter = wall_setter.get_setter()
logger.info("Getting the wallpapers using Unsplash API...")
paper_list = wall.get_list()
# If the dir is None, update it
if args.dir is None:
args.dir = "~/.cache/QuickWall"
set_paper = SetPaper(paper_list, setter, args.dir, args.disable_blacklist)
set_paper.do()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
logger.info("Keyboard Interrupt passed. Exiting..!")