Skip to content

Commit 7612ba3

Browse files
authored
refactor: refactor collector lua data build (#222)
1 parent 9e2fc78 commit 7612ba3

File tree

1 file changed

+63
-35
lines changed

1 file changed

+63
-35
lines changed

collect.py

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import time
1111
import typing
1212
from dataclasses import dataclass
13-
import luadata
1413

1514
import click
15+
import luadata
1616
from mdutils.mdutils import MdUtils
1717
from selenium.webdriver import Chrome, ChromeOptions
1818
from selenium.webdriver.common.by import By
@@ -641,36 +641,12 @@ def greater_than(a: ColorSpec, b: ColorSpec) -> bool:
641641
logging.debug(f"after dedup: {[str(s) for s in specs_set]}")
642642
return list(specs_set)
643643

644-
def build(self) -> None:
645-
self._download()
646-
# dedup candidates
647-
deduped_specs = self._dedup()
648-
649-
total = 0
650-
for spec in ColorSpec.all():
651-
if spec not in deduped_specs:
652-
logging.debug(f"remove for duplicate - repo:{spec}")
653-
spec.remove()
654-
else:
655-
total += 1
656-
657-
md = MdUtils(file_name="COLORSCHEMES", title=f"ColorSchemes List ({total})")
658-
all_specs = sorted(ColorSpec.all(), key=lambda s: s.github_stars, reverse=True)
659-
for i, spec in enumerate(all_specs):
660-
logging.info(f"collect spec-{i}:{spec}")
661-
color_names = spec.get_vim_color_names()
662-
color_names = sorted(color_names)
663-
md.new_line(
664-
f"- {md.new_inline_link(link=spec.url, text=spec.handle)} (stars: {spec.github_stars}, last update: {date_tostring(spec.last_git_commit)})"
665-
)
666-
for cname in color_names:
667-
md.new_line(f" - {cname}")
668-
md.create_md_file()
669-
644+
def _build_lua_specs(self, all_specs: list[ColorSpec]) -> None:
670645
lspecs = {}
671-
lspecsbycolorname = {}
672-
lspecsbygitpath = {}
646+
lspecs_by_colorname = {}
647+
lspecs_by_gitpath = {}
673648
lcolornames = []
649+
674650
for i, spec in enumerate(all_specs):
675651
logging.info(f"dump lua specs for spec-{i}:{spec}")
676652
lcolors = sorted(spec.get_vim_color_names())
@@ -686,16 +662,68 @@ def build(self) -> None:
686662
ColorSpec.COLOR_NAMES: lcolors,
687663
}
688664
lspecs[spec.handle] = lobj
689-
lspecsbygitpath[spec.git_path] = lobj
665+
lspecs_by_gitpath[spec.git_path] = lobj
690666
for j, color in enumerate(lcolors):
691667
lcolornames.append(color)
692-
lspecsbycolorname[color] = lobj
668+
lspecs_by_colorname[color] = lobj
693669

694670
lcolornames = sorted(lcolornames, key=lambda c: c.lower())
695-
luadata.write("lua/colorbox/meta/specs.lua", lspecs, encoding="utf-8", indent=" ", prefix = "return ")
696-
luadata.write("lua/colorbox/meta/specs_by_colorname.lua", lspecsbycolorname, encoding="utf-8", indent=" ", prefix = "return ")
697-
luadata.write("lua/colorbox/meta/specs_by_gitpath.lua", lspecsbygitpath, encoding="utf-8", indent=" ", prefix = "return ")
698-
luadata.write("lua/colorbox/meta/colornames.lua", lcolornames, encoding="utf-8", indent=" ", prefix = "return ")
671+
luadata.write(
672+
"lua/colorbox/meta/specs.lua",
673+
lspecs,
674+
encoding="utf-8",
675+
indent=" ",
676+
prefix="return ",
677+
)
678+
luadata.write(
679+
"lua/colorbox/meta/specs_by_colorname.lua",
680+
lspecs_by_colorname,
681+
encoding="utf-8",
682+
indent=" ",
683+
prefix="return ",
684+
)
685+
luadata.write(
686+
"lua/colorbox/meta/specs_by_gitpath.lua",
687+
lspecs_by_gitpath,
688+
encoding="utf-8",
689+
indent=" ",
690+
prefix="return ",
691+
)
692+
luadata.write(
693+
"lua/colorbox/meta/colornames.lua",
694+
lcolornames,
695+
encoding="utf-8",
696+
indent=" ",
697+
prefix="return ",
698+
)
699+
700+
def _build_md_list(self, all_specs: list[ColorSpec]) -> None:
701+
total = len(all_specs)
702+
md = MdUtils(file_name="COLORSCHEMES", title=f"ColorSchemes List ({total})")
703+
for i, spec in enumerate(all_specs):
704+
logging.info(f"collect spec-{i}:{spec}")
705+
color_names = spec.get_vim_color_names()
706+
color_names = sorted(color_names)
707+
md.new_line(
708+
f"- {md.new_inline_link(link=spec.url, text=spec.handle)} (stars: {spec.github_stars}, last update: {date_tostring(spec.last_git_commit)})"
709+
)
710+
for cname in color_names:
711+
md.new_line(f" - {cname}")
712+
md.create_md_file()
713+
714+
def build(self) -> None:
715+
self._download()
716+
# dedup candidates
717+
deduped_specs = self._dedup()
718+
719+
for spec in ColorSpec.all():
720+
if spec not in deduped_specs:
721+
logging.debug(f"remove for duplicate - repo:{spec}")
722+
spec.remove()
723+
724+
all_specs = sorted(ColorSpec.all(), key=lambda s: s.github_stars, reverse=True)
725+
self._build_md_list(all_specs)
726+
self._build_lua_specs(all_specs)
699727

700728

701729
@click.command()

0 commit comments

Comments
 (0)