Skip to content

Commit

Permalink
optimization: adjust startup parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
nondanee committed Sep 29, 2018
1 parent a9dec7f commit d9b6648
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 51 deletions.
25 changes: 11 additions & 14 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,26 @@ $ pip install futures #仅Python2需要

```
$ python weiboPicDownloader.py -h
usage: weiboPicDownloader [-h] [-u user] [-us users [users ...]] [-f file]
usage: weiboPicDownloader [-h] [-u user [user ...] | -f file [file ...]]
[-d directory] [-s size] [-r retry] [-c cookie] [-v]
[-o]
optional arguments:
-h, --help show this help message and exit
-u user specify a weibo user's nickname or id
-us users [users ...]
specify weibo users' nickname or id
-f file import user list from file
-d directory set picture saving path
-s size set size of thread pool
-r retry set maximum number of retries
-c cookie set cookie if needed
-v download videos together
-o overwrite existing files
-h, --help show this help message and exit
-u user [user ...] specify nickname or id of weibo users
-f file [file ...] import list of users from files
-d directory set picture saving path
-s size set size of thread pool
-r retry set maximum number of retries
-c cookie set cookie if needed
-v download videos together
-o overwrite existing files
```

必需参数(任选一)

- `-u user` 用户(昵称或ID)
- `-us users` 多个用户(昵称或ID,用空格分隔)
- `-f file` 用户列表文件(昵称或ID,用换行分隔)
- `-f file` 用户列表文件(昵称或ID,一个用户占一行)

可选参数

Expand Down
29 changes: 13 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,27 @@ $ pip install futures #only python2 environment required
## Usage

```
$ python weiboPicDownloader.py -h
usage: weiboPicDownloader [-h] [-u user] [-us users [users ...]] [-f file]
$ python .\weiboPicDownloader.py -h
usage: weiboPicDownloader [-h] [-u user [user ...] | -f file [file ...]]
[-d directory] [-s size] [-r retry] [-c cookie] [-v]
[-o]
optional arguments:
-h, --help show this help message and exit
-u user specify a weibo user's nickname or id
-us users [users ...]
specify weibo users' nickname or id
-f file import user list from file
-d directory set picture saving path
-s size set size of thread pool
-r retry set maximum number of retries
-c cookie set cookie if needed
-v download videos together
-o overwrite existing files
-h, --help show this help message and exit
-u user [user ...] specify nickname or id of weibo users
-f file [file ...] import list of users from files
-d directory set picture saving path
-s size set size of thread pool
-r retry set maximum number of retries
-c cookie set cookie if needed
-v download videos together
-o overwrite existing files
```

Required argument (choose one)

- `-u user` user (nickname or ID)
- `-us users` multiple users (nickname or ID, separated by space)
- `-f file` user list file (nickname or ID, separated by linefeed)
- `-u user ...` users (nickname or ID)
- `-f file ...` user list files (nickname or ID, separated by linefeed in the file)

Optional arguments

Expand Down
35 changes: 14 additions & 21 deletions weiboPicDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,14 @@
parser = argparse.ArgumentParser(
prog = "weiboPicDownloader"
)
parser.add_argument(
"-u", metavar = "user", dest = "user",
help = "specify a weibo user's nickname or id"
)
parser.add_argument(
"-us", metavar = "users", dest = "users", nargs = "+",
help = "specify weibo users' nickname or id"
group = parser.add_mutually_exclusive_group()
group.add_argument(
"-u", metavar = "user", dest = "users", nargs = '+',
help = "specify nickname or id of weibo users"
)
parser.add_argument(
"-f", metavar = "file", dest = "file",
help = "import user list from file"
group.add_argument(
"-f", metavar = "file", dest = "files", nargs = '+',
help = "import list of users from files"
)
parser.add_argument(
"-d", metavar = "directory", dest = "directory",
Expand Down Expand Up @@ -210,23 +207,19 @@ def download(url, file_path, overwrite):
return True

# users
if args.user:
if is_python2:
users = [args.user.decode(system_encodeing)]
else:
users = [args.user]
elif args.users:
if args.users:
if is_python2:
users = [user.decode(system_encodeing) for user in args.users]
users = [_user.decode(system_encodeing) for _user in args.users]
else:
users = args.users
elif args.file:
users = read_from_file(args.file)
elif args.files:
users = [read_from_file(_file) for _file in args.files]
users = reduce(lambda x, y : x + y, users)
else:
parser.print_help()
quit("miss user argument, -u, -us or -f is acceptable")
quit("\nmissing argument, you must provide at least one user")

# saving_path
# saving path
if args.directory:
saving_path = args.directory
if os.path.exists(saving_path):
Expand Down

0 comments on commit d9b6648

Please sign in to comment.