-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feature] support read config from env
- Loading branch information
1 parent
7d6a13a
commit 1678840
Showing
9 changed files
with
190 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,6 @@ dmypy.json | |
|
||
.DS_Store | ||
.idea/ | ||
bing/ | ||
database/ | ||
download/ | ||
storage/ | ||
log/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,57 @@ | ||
# bing_wallpaper | ||
A scripy to download bing daliy wallpaper | ||
|
||
A scripy to download bing daily wallpaper | ||
|
||
## Usage | ||
|
||
``` | ||
usage: app.py [-h] [--storage-dir STORAGE_DIR] [--download-dir DOWNLOAD_DIR] [--download-timeout DOWNLOAD_TIMEOUT] [--filelog] [--log-dir LOG_DIR] | ||
[--scan-interval SCAN_INTERVAL] [--notify-mail NOTIFY_MAIL] [--my-notify-mail MY_NOTIFY_MAIL] [--my-notify-pass MY_NOTIFY_PASS] | ||
[--my-notify-name MY_NOTIFY_NAME] [--server-chan-key SERVER_CHAN_KEY] | ||
A tool to download bing daily wallpaper. | ||
options: | ||
-h, --help show this help message and exit | ||
General Options: | ||
--storage-dir STORAGE_DIR | ||
directory to store database file, env: BING_STORAGE_DIR (default: storage) | ||
--download-dir DOWNLOAD_DIR | ||
directory to store image file, env: BING_DOWNLOAD_DIR (default: download) | ||
--download-timeout DOWNLOAD_TIMEOUT | ||
download timeout ms, env: BING_DOWNLOAD_TIMEOUT (default: 5000) | ||
--filelog write log to file, otherwise to stdout (default: False) | ||
--log-dir LOG_DIR directory to store log file if filelog is true, env: BING_LOG_DIR (default: log) | ||
--scan-interval SCAN_INTERVAL | ||
every scan-interval seconds to get bing wallpaper, 0 means run once, env: BING_SCAN_INTERVAL (default: 0) | ||
Notify Options: | ||
--notify-mail NOTIFY_MAIL | ||
email to notify when success or failed download, env: BING_NOTIFY_MAIL (default: None) | ||
--my-notify-mail MY_NOTIFY_MAIL | ||
email to send notify email, env: BING_MY_NOTIFY_MAIL (default: None) | ||
--my-notify-pass MY_NOTIFY_PASS | ||
my-email password or token, env: BING_MY_NOTIFY_PASS (default: None) | ||
--my-notify-name MY_NOTIFY_NAME | ||
user name to send notify email, env: BING_MY_NOTIFY_NAME (default: Robot) | ||
--server-chan-key SERVER_CHAN_KEY | ||
server-chan token to notify, env: BING_SERVER_CHAN_KEY (default: None) | ||
``` | ||
|
||
All args can be read from environment variables, the environment variables with prefix `BING_`. | ||
|
||
## Docker Usage | ||
|
||
```shell | ||
docker run -d \ | ||
-v /path/to/config/folder:/bing/config \ | ||
-v /path/to/database/folder:/bing/database \ | ||
-v /path/to/download/folder:/bing/wallpaper \ | ||
-e BING_SCAN_INTERVAL=3600 \ | ||
-e [email protected] \ | ||
-e [email protected] \ | ||
-e BING_MY_NOTIFY_PASS=password \ | ||
-e BING_SERVER_CHAN_KEY=xxx \ | ||
-v /path/to/storage/folder:/bing/storage \ | ||
-v /path/to/download/folder:/bing/download \ | ||
littleneko/bing-dl:latest | ||
``` |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
"""Provides a utility to inject environment variables into argparse definitions. | ||
Currently requires explicit naming of env vars to check for""" | ||
|
||
# https://gist.github.com/orls/51525c86ee77a56ad396 | ||
|
||
import argparse | ||
import os | ||
|
||
|
||
# Courtesy of http://stackoverflow.com/a/10551190 with env-var retrieval fixed | ||
class EnvDefault(argparse.Action): | ||
"""An argparse action class that auto-sets missing default values from env | ||
vars. Defaults to requiring the argument.""" | ||
|
||
def __init__(self, env_var, required=False, default=None, **kwargs): | ||
if env_var and env_var in os.environ: | ||
var = os.environ[env_var] | ||
if len(var) > 0: | ||
default = var | ||
if required and default: | ||
required = False | ||
super(EnvDefault, self).__init__(default=default, required=required, **kwargs) | ||
|
||
def __call__(self, parser, namespace, values, option_string=None): | ||
setattr(namespace, self.dest, values) | ||
|
||
|
||
# functional sugar for the above | ||
def env_default(env_var): | ||
def wrapper(**kwargs): | ||
return EnvDefault(env_var, **kwargs) | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.