Skip to content

Commit

Permalink
[Issue #302] Cli supports multiple filters and enhance the printed ou…
Browse files Browse the repository at this point in the history
…tput (#303)

* [ADD] conf CSCW2024

* ccfddl-cli: suport multiple filter conditions

- parse multiple fitlers
- add help info for args
- minor change for filter logic

Fix [Issue #302](#302)

* ccfddl-cli: time left more human-centric

    - show left time using `humanize`.
    - update doc and requirements.

    Fix [Issue #302](#302)

* ccfddl-cli: colored left time

    - colorize text according how much time left
    - update req
    - minor: captalize the header

    Fix [Issue #302](#302)

* [Update] main Readme python-cli screenshot.
  • Loading branch information
ViGeng authored Sep 18, 2023
1 parent cc051f5 commit 6a23710
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
Binary file modified .readme_assets/screenshot_pycli.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 55 additions & 12 deletions cli/ccfddl/__main__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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'))

Expand Down
12 changes: 9 additions & 3 deletions cli/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ WIP

## install

```
```bash
pip install -r req.txt
python setup.py install
```

## usage

```
```bash
python -m ccfddl
```
```

| 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` |
1 change: 1 addition & 0 deletions cli/req.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ tabulate
yaml
pyyaml
requests
termcolor

0 comments on commit 6a23710

Please sign in to comment.