diff --git a/proxy_scraper_checker/__main__.py b/proxy_scraper_checker/__main__.py index 9eb7355..d01cca6 100644 --- a/proxy_scraper_checker/__main__.py +++ b/proxy_scraper_checker/__main__.py @@ -82,9 +82,9 @@ def get_summary_table( table.add_column("Working", style="magenta") table.add_column("Total", style="green") for proto in sort.PROTOCOL_ORDER: - if total := before.get(proto): + if (total := before.get(proto)) is not None: working = after.get(proto, 0) - percentage = working / total + percentage = (working / total) if total else 0 table.add_row( proto.name, f"{working} ({percentage:.1%})", str(total) ) diff --git a/proxy_scraper_checker/storage.py b/proxy_scraper_checker/storage.py index 2f53e36..7befdcf 100644 --- a/proxy_scraper_checker/storage.py +++ b/proxy_scraper_checker/storage.py @@ -26,17 +26,29 @@ class ProxyStorage: def get_grouped(self) -> Dict[ProxyType, Tuple[Proxy, ...]]: key = sort.protocol_sort_key - d: Dict[ProxyType, Tuple[Proxy, ...]] = { - proto: () - for proto in sort.PROTOCOL_ORDER - if proto in self.enabled_protocols + return { + **{ + proto: () + for proto in sort.PROTOCOL_ORDER + if proto in self.enabled_protocols + }, + **{ + proto: tuple(v) + for (_, proto), v in itertools.groupby( + sorted(self, key=key), key=key + ) + }, } - for (_, proto), v in itertools.groupby(sorted(self, key=key), key=key): - d[proto] = tuple(v) - return d def get_count(self) -> Dict[ProxyType, int]: - return dict(Counter(proxy.protocol for proxy in self)) + return { + **{ + proto: 0 + for proto in sort.PROTOCOL_ORDER + if proto in self.enabled_protocols + }, + **Counter(proxy.protocol for proxy in self), + } def __iter__(self) -> Iterator[Proxy]: return iter(self._proxies)