from sys import argv from os import path, mkdir from shutil import rmtree channels = argv[1:] if not path.isdir('data'): print("Creating data") mkdir('data') if path.isfile('data/channels.txt'): file = open('data/channels.txt', 'r+') existing = [c.strip() for c in file] # print(existing) else: file = open('data/channels.txt', 'w') existing = [] if channels == []: if existing == []: print("No channels") else: print("Channels: " + ','.join(existing)) for ch in channels: remove = ch.startswith('-') if remove: ch = ch[1:] if ch not in existing: print(f"Channel {ch} doesn't exist") continue rmtree('data/' + ch) existing.remove(ch) file.truncate(0) file.seek(0) file.writelines([e + '\n' for e in existing]) print("Removed " + ch) else: if ch in existing: print(f"Channel {ch} already exists") continue file.write(ch + '\n') try: mkdir('data/' + ch) except FileExistsError: print(f"Channel {ch} already exists but wasn't in channels.txt, now added") existing += [ch] print("Created " + ch)