45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
|
#!/usr/bin/env python3
|
||
|
# -*- encoding: utf-8 -*-
|
||
|
|
||
|
import json
|
||
|
from pathlib import Path
|
||
|
from typing import Dict, List
|
||
|
|
||
|
import colored
|
||
|
|
||
|
from .system.cmdline_parser import parse_cmdline
|
||
|
|
||
|
|
||
|
def cmdline(encoded_args: str = None):
|
||
|
if encoded_args is None:
|
||
|
return run_with_config()
|
||
|
else:
|
||
|
return parse_cmdline(run_with_config, encoded_args)
|
||
|
|
||
|
|
||
|
def run_with_config():
|
||
|
main()
|
||
|
|
||
|
|
||
|
def main():
|
||
|
not_downloadable_links: Dict[str, List[str]] = json.loads(
|
||
|
Path('i_undownloadable.json').read_text())
|
||
|
subreddits_untreated = not_downloadable_links.get('reddit_subreddit', [])
|
||
|
subreddits_set = set()
|
||
|
subreddits = list()
|
||
|
for subreddit_untreated in subreddits_untreated:
|
||
|
subreddit = subreddit_untreated.split('/r/')[1].split('/')[0].split('?')[0].split('#')[0].lower()
|
||
|
if subreddit not in subreddits_set:
|
||
|
subreddits_set.add(subreddit)
|
||
|
subreddits.append((not Path('r', subreddit).exists(), subreddit))
|
||
|
del subreddit_untreated
|
||
|
del subreddit
|
||
|
del subreddits_set
|
||
|
subreddits.sort()
|
||
|
for missing, subreddit in subreddits:
|
||
|
print(colored.stylize('https://www.reddit.com/', [colored.fg('cyan'), ]), end='')
|
||
|
print(colored.stylize('r/', [colored.fg('magenta'), ]), end='')
|
||
|
print(colored.stylize(subreddit, [
|
||
|
colored.fg('red' if missing else 'light_green'),
|
||
|
]))
|