From 1e535c1b0cd3fd8831c1fa3cbfc26f6a7c6d0ebf Mon Sep 17 00:00:00 2001 From: surister Date: Thu, 9 Jan 2020 12:12:42 +0100 Subject: [PATCH] Add update question number script --- scripts/update_question_number.py | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 scripts/update_question_number.py diff --git a/scripts/update_question_number.py b/scripts/update_question_number.py new file mode 100644 index 0000000..7499fbd --- /dev/null +++ b/scripts/update_question_number.py @@ -0,0 +1,32 @@ +""" +Meant to be used like this: + +python scripts/update_question_number.py + +""" +import pathlib +from scripts.question_utils import get_question_list, get_challenges_count + +LINE_FLAG = b":bar_chart:" + +p = pathlib.Path(__file__).parent.parent.joinpath('README.md') + + +with open(p, 'rb') as f: + file = f.readlines() + + +file_list = [line.rstrip() for line in file] + +question_list = get_question_list(file_list) +question_count = len(question_list) +total_count = question_count + get_challenges_count() + +for line in file: + if LINE_FLAG in line: + file[file.index(line)] = b':bar_chart:  There are currently **%s** questions\r\n' %\ + str(total_count).encode() + break + +with open(p, 'wb') as f: + f.writelines(file)