1 Star 0 Fork 1

天马行空/QuickWall

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
QuickWall.py 3.55 KB
一键复制 编辑 原始数据 按行查看 历史
#!/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..!")
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/IMGet/QuickWall.git
git@gitee.com:IMGet/QuickWall.git
IMGet
QuickWall
QuickWall
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385