From a244813526844f2fe94fcdf14f3a81f36774c6fa Mon Sep 17 00:00:00 2001 From: sgoudham Date: Tue, 28 Jul 2020 00:03:28 +0100 Subject: [PATCH] Splitting lines of code into Code/Blank/Commentary/Total/Files --- cogs/info.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/cogs/info.py b/cogs/info.py index 891f72b0..8a70a08f 100644 --- a/cogs/info.py +++ b/cogs/info.py @@ -54,7 +54,11 @@ def DetectPermissions(message, fset): def lineCount(): - total = 0 + """Getting the line count of the project""" + + code = 0 + comments = 0 + blank = 0 file_amount = 0 ENV = "venv" # change this to your env folder dir @@ -66,10 +70,21 @@ def lineCount(): file_amount += 1 with open(file_dir, "r", encoding="utf-8") as file: for line in file: - if not line.strip().startswith("#") or not line.strip(): - total += 1 - - return "{} Lines | {} Files".format(total, file_amount) + if line.strip().startswith("#"): + comments += 1 + elif not line.strip(): + blank += 1 + else: + code += 1 + + # Adding up the total lines of code + total = comments + blank + code + + return "Code: {}\n " \ + "Commentary: {}\n" \ + "Blank: {}\n" \ + "Total: {}\n" \ + "Files: {}".format(code, comments, blank, total, file_amount) class Info(commands.Cog):