diff --git a/.readme_assets/screenshot_pycli.png b/.readme_assets/screenshot_pycli.png index b1cfbbad..d5eec507 100644 Binary files a/.readme_assets/screenshot_pycli.png and b/.readme_assets/screenshot_pycli.png differ diff --git a/cli/ccfddl/__main__.py b/cli/ccfddl/__main__.py index 02fff853..dca71a92 100755 --- a/cli/ccfddl/__main__.py +++ b/cli/ccfddl/__main__.py @@ -1,5 +1,7 @@ +import string import requests import yaml +from termcolor import colored from argparse import ArgumentParser from copy import deepcopy from datetime import datetime @@ -20,15 +22,43 @@ def parse_tz(tz): def parse_args(): parser = ArgumentParser(description="cli for ccfddl") - parser.add_argument("--conf", type=str) - parser.add_argument("--sub", type=str) - parser.add_argument("--rank", type=str) - return parser.parse_args() + parser.add_argument("--conf", type=str, nargs='+', + help="A list of conference ids you want to filter, e.g.: '--conf CVPR ICML'") + parser.add_argument("--sub", type=str, nargs='+', + help="A list of subcategories ids you want to filter, e.g.: '--sub AI CG'") + parser.add_argument("--rank", type=str, nargs='+', + help="A list of ranks you want to filter, e.g.: '--rank C N'") + args = parser.parse_args() + # Convert all arguments to lowercase + for arg_name in vars(args): + arg_value = getattr(args, arg_name) + if arg_value: + setattr(args, arg_name, [arg.lower() for arg in arg_value]) + return args + + +def format_duraton(ddl_time: datetime, now: datetime) -> str: + duration = ddl_time - now + months, days= duration.days // 30, duration.days + hours, remainder= divmod(duration.seconds, 3600) + minutes, seconds = divmod(remainder, 60) + + day_word_str = "days" if days > 1 else "day " + # for alignment + months_str, days_str, = str(months).zfill(2), str(days).zfill(2) + hours_str, minutes_str = str(hours).zfill(2), str(minutes).zfill(2) + + if days < 1: + return colored(f'{hours_str}:{minutes_str}:{seconds}', "red") + if days < 30: + return colored(f'{days_str} {day_word_str}, {hours_str}:{minutes_str}', "yellow") + if days < 100: + return colored(f"{days_str} {day_word_str}", "blue") + return colored(f"{months_str} months", "green") def main(): args = parse_args() - yml_str = requests.get( "https://ccfddl.github.io/conference/allconf.yml").content.decode("utf-8") all_conf = yaml.safe_load(yml_str) @@ -59,18 +89,31 @@ def main(): all_conf_ext = sorted(all_conf_ext, key=lambda x: x['time_obj']) - table = [["title", "sub", "rank", "ddl", "link"]] + # This is not an elegant solution. + # The purpose is to keep the above logic untouched, + # return alpha id(conf name) without digits(year) + def alpha_id(with_digits: string) -> string: + return ''.join(char for char in with_digits.lower() if char.isalpha()) + + table = [["Title", "Sub", "Rank", "DDL", "Link"]] + # Filter intersection by args for x in all_conf_ext: skip = False - if args.conf and args.conf.lower() not in x["id"].lower(): + if args.conf and alpha_id(x["id"]) not in args.conf: skip = True - if args.sub and args.sub.lower() not in x["sub"].lower(): + if args.sub and alpha_id(x["sub"]) not in args.sub: skip = True - if args.rank and args.rank.lower() not in x["rank"].lower(): + if args.rank and alpha_id(x["rank"]) not in args.rank: skip = True - if not skip: - table.append([x["title"], x["sub"], x["rank"], - str(x["time_obj"] - now), x["link"]]) + if skip: + continue + table.append( + [x["title"], + x["sub"], + x["rank"], + format_duraton(x["time_obj"], now), + x["link"]] + ) print(tabulate(table, headers='firstrow', tablefmt='fancy_grid')) diff --git a/cli/readme.md b/cli/readme.md index 664b7581..579296cf 100755 --- a/cli/readme.md +++ b/cli/readme.md @@ -4,13 +4,19 @@ WIP ## install -``` +```bash pip install -r req.txt python setup.py install ``` ## usage -``` +```bash python -m ccfddl -``` \ No newline at end of file +``` + +| Argument | Type | Description | Example | +| -------- | ----- | ------------------------------------ | ------------------ | +| `--conf` | str[] | A list of conference IDs to filter. | `--conf CVPR ICCV` | +| `--sub` | str[] | A list of subcategory IDs to filter. | `--sub AI ML` | +| `--rank` | str[] | A list of ranks to filter. | `--rank A B` | diff --git a/cli/req.txt b/cli/req.txt index 7934bdef..b1a4bdcb 100644 --- a/cli/req.txt +++ b/cli/req.txt @@ -2,3 +2,4 @@ tabulate yaml pyyaml requests +termcolor