diff options
author | Anthony Wang | 2022-01-22 22:13:20 -0600 |
---|---|---|
committer | Anthony Wang | 2022-01-22 22:13:20 -0600 |
commit | 2cfefc2d005283c8875e402622373c77e86fe9f4 (patch) | |
tree | f5875a2dda91434d50ebc12e6bb9a8c8dcd97ea0 | |
parent | b292414cfda5f81805c557b6d0023590ef6205c1 (diff) |
Clean up mkbinder.py logic
-rwxr-xr-x | mkbinder.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/mkbinder.py b/mkbinder.py index eddca9e..1222376 100755 --- a/mkbinder.py +++ b/mkbinder.py @@ -16,19 +16,19 @@ parser.add_argument('--force', '-f', help = 'force download all links', action=' args = parser.parse_args() -for filename in os.listdir('Links'): - print('Examining: ' + filename) - os.makedirs(filename, exists_ok=True) +for category in os.listdir('Links'): + print('Examining: ' + category) + os.makedirs(category, exist_ok=True) section = '' - for link in open(os.path.join('Links', filename), 'r').readlines(): + for link in open(os.path.join('Links', category), 'r').readlines(): if link[0:2] == '# ': - section = link[2:] + section = link[2:-1] if link[0] == '#' or link[0] == '\n': continue - name = section + ' - ' + re.sub(r'(?u)[^-\w.]', '', link[5:]) + '.pdf' - if not os.path.exists(os.path.join('Links', name)) or args.force: + name = os.path.join(category, section + ' - ' + re.sub(r'(?u)[^-\w.]', '', link[5:]) + '.pdf') + if not os.path.exists(name) or args.force: print('Downloading: ' + link[:-1]) print('Destination: ' + name) |