fix 'dir' variable names shadowing dir(); add noinspection comments

(shut pycharm's mouth)
This commit is contained in:
Tomáš Mládek 2019-05-15 11:21:35 +02:00
parent 949008cb05
commit 6300ed6438

View file

@ -156,6 +156,7 @@ class DelojzaBot:
id3.add(mutagen.id3.TPE1(encoding=3, text=artist)) id3.add(mutagen.id3.TPE1(encoding=3, text=artist))
id3.save() id3.save()
# noinspection PyUnusedLocal
def download_ytdl(self, urls, out_path, date, message, audio=False, filename=None): def download_ytdl(self, urls, out_path, date, message, audio=False, filename=None):
ydl_opts = { ydl_opts = {
'noplaylist': True, 'noplaylist': True,
@ -336,19 +337,19 @@ class DelojzaBot:
def tag_dirs(self): def tag_dirs(self):
return list(filter(lambda x: x.upper() == x, return list(filter(lambda x: x.upper() == x,
filter(lambda dir: os.path.isdir(os.path.join(self.out_dir, dir)), filter(lambda directory: os.path.isdir(os.path.join(self.out_dir, directory)),
os.listdir(self.out_dir)))) os.listdir(self.out_dir))))
def tg_stats(self, _, update): def tg_stats(self, _, update):
tag_dirs = self.tag_dirs() tag_dirs = self.tag_dirs()
reply = "Total number of tags: {}\n\n".format(len(tag_dirs)) reply = "Total number of tags: {}\n\n".format(len(tag_dirs))
counts = [(dir, os.listdir(os.path.join(self.out_dir, dir))) for dir in tag_dirs] counts = [(directory, os.listdir(os.path.join(self.out_dir, directory))) for directory in tag_dirs]
counts.sort(key=itemgetter(0)) counts.sort(key=itemgetter(0))
counts.sort(key=lambda x: len(x[1]), reverse=True) counts.sort(key=lambda x: len(x[1]), reverse=True)
for dir, files in counts: for directory, files in counts:
if len(files) == 1: if len(files) == 1:
break break
abs_paths = [os.path.join(self.out_dir, dir, file) for file in files] abs_paths = [os.path.join(self.out_dir, directory, file) for file in files]
abs_files = list(filter(os.path.isfile, abs_paths)) abs_files = list(filter(os.path.isfile, abs_paths))
# mimes = [magic.from_file(path, mime=True).split("/")[0] for path in abs_files] # mimes = [magic.from_file(path, mime=True).split("/")[0] for path in abs_files]
# mime_counts = [(mime, mimes.count(mime)) for mime in set(mimes)] # mime_counts = [(mime, mimes.count(mime)) for mime in set(mimes)]
@ -359,9 +360,9 @@ class DelojzaBot:
details = ", ".join(["{} {}s".format(cnt, mime) for mime, cnt in details = ", ".join(["{} {}s".format(cnt, mime) for mime, cnt in
sorted(type_counts, key=itemgetter(1), reverse=True)]) sorted(type_counts, key=itemgetter(1), reverse=True)])
if len(type_counts) == 1: if len(type_counts) == 1:
reply += "<b>{}:</b> {}\n".format(dir, details) reply += "<b>{}:</b> {}\n".format(directory, details)
else: else:
reply += "<b>{}:</b> {} files ({})\n".format(dir, len(files), details) reply += "<b>{}:</b> {} files ({})\n".format(directory, len(files), details)
orphans = list(filter(lambda cnt: len(cnt[1]) <= 1, counts)) orphans = list(filter(lambda cnt: len(cnt[1]) <= 1, counts))
if len(orphans) > 0: if len(orphans) > 0:
reply += "\nFollowing tags are orphans: " + ", ".join(map(itemgetter(0), orphans)) reply += "\nFollowing tags are orphans: " + ", ".join(map(itemgetter(0), orphans))
@ -370,12 +371,12 @@ class DelojzaBot:
def orphans(self): def orphans(self):
result = [] result = []
tag_dirs = self.tag_dirs() tag_dirs = self.tag_dirs()
for dir in tag_dirs: for directory in tag_dirs:
files = os.listdir(os.path.join(self.out_dir, dir)) files = os.listdir(os.path.join(self.out_dir, directory))
if len(files) == 1: if len(files) == 1:
result.append((dir, files[0])) result.append((directory, files[0]))
if len(files) == 0: if len(files) == 0:
result.append((dir, "NO FILE AT ALL...")) result.append((directory, "NO FILE AT ALL..."))
return sorted(result, key=itemgetter(0)) return sorted(result, key=itemgetter(0))
def tg_orphan(self, _, update): def tg_orphan(self, _, update):
@ -392,8 +393,8 @@ class DelojzaBot:
update.message.reply_text("Good job, no orphan tags!") update.message.reply_text("Good job, no orphan tags!")
else: else:
tmp_reply = "The following tags only contain a single file:\n" tmp_reply = "The following tags only contain a single file:\n"
for dir, file in orphans: for directory, file in orphans:
line = "{}: {}\n".format(dir, file) line = "{}: {}\n".format(directory, file)
if len(tmp_reply + line) > 4096: if len(tmp_reply + line) > 4096:
update.message.reply_text(tmp_reply) update.message.reply_text(tmp_reply)
tmp_reply = "" tmp_reply = ""
@ -426,6 +427,7 @@ class DelojzaBot:
else: else:
update.message.reply_text("Nothing to remove!") update.message.reply_text("Nothing to remove!")
# noinspection PyMethodMayBeStatic
def tg_version(self, _, update): def tg_version(self, _, update):
delojza_date = datetime.fromtimestamp(os.path.getmtime(os.path.realpath(__file__))) \ delojza_date = datetime.fromtimestamp(os.path.getmtime(os.path.realpath(__file__))) \
.strftime('%Y/%m/%d - %H:%M:%S') .strftime('%Y/%m/%d - %H:%M:%S')