From a366348ab85b080fe5916fceb014575ef069643f Mon Sep 17 00:00:00 2001 From: blackmamoth Date: Mon, 5 Jun 2023 00:36:35 +0530 Subject: [PATCH 1/5] Wrote a function to replace html escape characters in question titles to their corresponding ascii characters --- dynamic/utility.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index 9faf891..009f8ae 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -33,6 +33,9 @@ from webdriver_manager.firefox import GeckoDriverManager from webdriver_manager.microsoft import EdgeChromiumDriverManager +# Required for replacing html escape characters with their corresponding ascii characters +import html + console = Console() @@ -183,6 +186,18 @@ def __init__(self): self.utility = Utility() self.playbook = Playbook() + def replaceHtmlEscapeCharacters(self, question_title): + """ + Function to replace HTML escape characters in question's title + to their corresponding ASCII characters + For example, if the title was something like this: + '"static const" vs "#define" vs "enum"' + the HTML escape characters would be replaced with their corresponding ASCII + characters and the resulting string would be: + '"static const" vs "#define" vs "enum"' + """ + return html.unescape(question_title) + def populate_question_data(self, questions_list): """ Function to populate question data property @@ -199,7 +214,7 @@ def populate_question_data(self, questions_list): sys.exit() json_ques_data = resp.json() self.questions_data = [ - [item["title"].replace("|", ""), item["question_id"], item["link"]] + [self.replaceHtmlEscapeCharacters(item["title"].replace("|", "")), item["question_id"], item["link"]] for item in json_ques_data["items"] ] From f5d944a99bf7923a8916d2837365e0a3d9a20284 Mon Sep 17 00:00:00 2001 From: blackmamoth Date: Mon, 5 Jun 2023 13:06:40 +0530 Subject: [PATCH 2/5] made changes as the requirements --- dynamic/utility.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index 009f8ae..62262fa 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -1,3 +1,5 @@ +# Required for replacing html escape characters with their corresponding ascii characters +import html from termcolor import colored import requests from rich.console import Console @@ -33,8 +35,7 @@ from webdriver_manager.firefox import GeckoDriverManager from webdriver_manager.microsoft import EdgeChromiumDriverManager -# Required for replacing html escape characters with their corresponding ascii characters -import html + console = Console() @@ -186,7 +187,7 @@ def __init__(self): self.utility = Utility() self.playbook = Playbook() - def replaceHtmlEscapeCharacters(self, question_title): + def unescape_html_characters(self, question_title): """ Function to replace HTML escape characters in question's title to their corresponding ASCII characters @@ -214,7 +215,7 @@ def populate_question_data(self, questions_list): sys.exit() json_ques_data = resp.json() self.questions_data = [ - [self.replaceHtmlEscapeCharacters(item["title"].replace("|", "")), item["question_id"], item["link"]] + [self.unescape_html_characters(item["title"].replace("|", "")), item["question_id"], item["link"]] for item in json_ques_data["items"] ] From 5cf712e3831defddddcdc25e6090258f44cf5d7b Mon Sep 17 00:00:00 2001 From: blackmamoth Date: Thu, 8 Jun 2023 14:27:44 +0530 Subject: [PATCH 3/5] made changes according to pylint --- dynamic/utility.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index 62262fa..8f06547 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -1,5 +1,6 @@ -# Required for replacing html escape characters with their corresponding ascii characters +""" Required for replacing html escape characters with their corresponding unicode/ascii characters """ import html + from termcolor import colored import requests from rich.console import Console @@ -187,18 +188,6 @@ def __init__(self): self.utility = Utility() self.playbook = Playbook() - def unescape_html_characters(self, question_title): - """ - Function to replace HTML escape characters in question's title - to their corresponding ASCII characters - For example, if the title was something like this: - '"static const" vs "#define" vs "enum"' - the HTML escape characters would be replaced with their corresponding ASCII - characters and the resulting string would be: - '"static const" vs "#define" vs "enum"' - """ - return html.unescape(question_title) - def populate_question_data(self, questions_list): """ Function to populate question data property @@ -206,6 +195,8 @@ def populate_question_data(self, questions_list): details of questions with id in the list. Stores the returned data in the following format: list( list( question_title, question_link, question_id ) ) + User html.unescape function to convert html character references + to the corresponding unicode to corresponding unicode characters """ with console.status("Getting the questions..."): try: @@ -215,7 +206,7 @@ def populate_question_data(self, questions_list): sys.exit() json_ques_data = resp.json() self.questions_data = [ - [self.unescape_html_characters(item["title"].replace("|", "")), item["question_id"], item["link"]] + [html.unescape(item["title"].replace("|", "")), item["question_id"], item["link"]] for item in json_ques_data["items"] ] From a5fc7eeb4f8982c4896f3c63f8d7dab0e70165ec Mon Sep 17 00:00:00 2001 From: blackmamoth Date: Thu, 8 Jun 2023 14:29:12 +0530 Subject: [PATCH 4/5] typo in docstring --- dynamic/utility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index 8f06547..2855aea 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -195,7 +195,7 @@ def populate_question_data(self, questions_list): details of questions with id in the list. Stores the returned data in the following format: list( list( question_title, question_link, question_id ) ) - User html.unescape function to convert html character references + Uses html.unescape function to convert html character references to the corresponding unicode to corresponding unicode characters """ with console.status("Getting the questions..."): From 1124ff22da75fcd8035a8446bd80f1a29b340d24 Mon Sep 17 00:00:00 2001 From: blackmamoth Date: Thu, 8 Jun 2023 14:33:40 +0530 Subject: [PATCH 5/5] made 1 more change according to pylint --- dynamic/utility.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index 2855aea..0fb6e00 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -1,4 +1,5 @@ -""" Required for replacing html escape characters with their corresponding unicode/ascii characters """ +""" Required for replacing html escape characters with their + corresponding unicode/ascii characters """ import html from termcolor import colored