From 8249846eb4b4c8a2bca076c548c28b78b415f82c Mon Sep 17 00:00:00 2001 From: ASHUTOSH <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Tue, 11 Oct 2022 01:27:04 +0530 Subject: [PATCH 01/22] Link your codeforces profile with cli --- COMMANDS.md | 9 +++++++++ src/Cli/cli.py | 5 +++-- src/Cli/profile.py | 22 ++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 src/Cli/profile.py diff --git a/COMMANDS.md b/COMMANDS.md index a090b34..d65dc28 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -20,6 +20,15 @@ This will change the runtime environment. Currently value of `` can only be 'python' or 'cpp' are supported +* ``` + ecp profile + ``` + Example: + ``` + ecp profile tourist + ``` + This will make a profile card in the terminal. + * ``` ecp config set-proxy ``` diff --git a/src/Cli/cli.py b/src/Cli/cli.py index 9abaff9..1573ee1 100644 --- a/src/Cli/cli.py +++ b/src/Cli/cli.py @@ -7,7 +7,7 @@ from .runner import run from .config import config from .test import test - +from .profile import profile @click.group() def entry_point(): pass @@ -15,4 +15,5 @@ def entry_point(): entry_point.add_command(problem) entry_point.add_command(run) entry_point.add_command(config) -entry_point.add_command(test) \ No newline at end of file +entry_point.add_command(test) +entry_point.add_command(profile) \ No newline at end of file diff --git a/src/Cli/profile.py b/src/Cli/profile.py new file mode 100644 index 0000000..daa290b --- /dev/null +++ b/src/Cli/profile.py @@ -0,0 +1,22 @@ +import requests +import click + +@click.command() +@click.argument('user',type=str) +def profile(user): + try: + response = requests.get(url='http://codeforces.com/api/user.info?handles='+user) + if(response.status_code!=200): + raise UsernameError('User not Found') + html_content = response.json() + print("*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-") + print( + "User Name : " + html_content["result"][0]["firstName"] + html_content["result"][0]["lastName"], + "\nRating : " + str(html_content["result"][0]["rating"]), + "\nContribution : " + str(html_content["result"][0]["contribution"]), + "\nRank : " + str(html_content["result"][0]["rank"]), + "\nMax Rating : " + str(html_content["result"][0]["maxRating"]) + ) + print("*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-") + except Exception() as e: + click.echo(e) \ No newline at end of file From ea7f49fb740a74e8578ffc9025769a14e6eb3f90 Mon Sep 17 00:00:00 2001 From: ASHUTOSH <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Tue, 11 Oct 2022 21:06:48 +0530 Subject: [PATCH 02/22] added necessary chancges to link wiith cofeforces profile --- COMMANDS.md | 17 +++++++++++++---- src/Cli/cli.py | 4 +--- src/Cli/config.py | 21 ++++++++++++++++++++- src/Cli/profile.py | 22 ---------------------- src/Config/Config.py | 33 +++++++++++++++++++++++++++++++++ src/Config/config.json | 2 +- 6 files changed, 68 insertions(+), 31 deletions(-) delete mode 100644 src/Cli/profile.py diff --git a/COMMANDS.md b/COMMANDS.md index d65dc28..dcb19e6 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -21,14 +21,23 @@ Currently value of `` can only be 'python' or 'cpp' are supported * ``` - ecp profile + ecp config set_user ``` Example: ``` - ecp profile tourist + ecp config get_user tourist ``` - This will make a profile card in the terminal. - + This fetch info about the user from config.json file. + +* ``` + ecp config get_user + ``` + Example: + ``` + ecp config get_user + ``` + This will add necessary info about the user to config.json file. + * ``` ecp config set-proxy ``` diff --git a/src/Cli/cli.py b/src/Cli/cli.py index 1573ee1..1c908cb 100644 --- a/src/Cli/cli.py +++ b/src/Cli/cli.py @@ -7,7 +7,6 @@ from .runner import run from .config import config from .test import test -from .profile import profile @click.group() def entry_point(): pass @@ -15,5 +14,4 @@ def entry_point(): entry_point.add_command(problem) entry_point.add_command(run) entry_point.add_command(config) -entry_point.add_command(test) -entry_point.add_command(profile) \ No newline at end of file +entry_point.add_command(test) \ No newline at end of file diff --git a/src/Cli/config.py b/src/Cli/config.py index f8bf736..6b51cbf 100644 --- a/src/Cli/config.py +++ b/src/Cli/config.py @@ -66,8 +66,27 @@ def remove_proxy(): except Exception as e: click.echo(e) +@click.command() +@click.argument("user",type=str) +def set_user(user): + try: + config = Config() + config.set_user(user) + click.echo(click.style('User information have been fetched.', fg='green')) + except Exception as e: + click.echo(e) +@click.command() +def get_user(): + try: + config = Config() + config.get_user() + except Exception as e: + click.echo(e) + config.add_command(get_lang) config.add_command(set_lang) config.add_command(set_temp) config.add_command(set_proxy) -config.add_command(remove_proxy) \ No newline at end of file +config.add_command(remove_proxy) +config.add_command(set_user) +config.add_command(get_user) \ No newline at end of file diff --git a/src/Cli/profile.py b/src/Cli/profile.py deleted file mode 100644 index daa290b..0000000 --- a/src/Cli/profile.py +++ /dev/null @@ -1,22 +0,0 @@ -import requests -import click - -@click.command() -@click.argument('user',type=str) -def profile(user): - try: - response = requests.get(url='http://codeforces.com/api/user.info?handles='+user) - if(response.status_code!=200): - raise UsernameError('User not Found') - html_content = response.json() - print("*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-") - print( - "User Name : " + html_content["result"][0]["firstName"] + html_content["result"][0]["lastName"], - "\nRating : " + str(html_content["result"][0]["rating"]), - "\nContribution : " + str(html_content["result"][0]["contribution"]), - "\nRank : " + str(html_content["result"][0]["rank"]), - "\nMax Rating : " + str(html_content["result"][0]["maxRating"]) - ) - print("*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-*-*-*-*-") - except Exception() as e: - click.echo(e) \ No newline at end of file diff --git a/src/Config/Config.py b/src/Config/Config.py index 68022ad..440cc04 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -1,5 +1,6 @@ import json import os +import requests from pathlib import Path from ..Runner.exceptions.UnsupportedLanguage import UnsupportedLanguage @@ -88,3 +89,35 @@ def remove_proxy(self): config_file.seek(0) config_file.truncate() config_file.write(json.dumps(config)) + + def set_user(self, user): + response = requests.get(url='http://codeforces.com/api/user.info?handles='+user,proxies=self.get_proxy()) + if(response.status_code!=200): + raise UsernameError('User not Found') + html_content = response.json() + config_file_path = self.config_file_path + with open(config_file_path, 'r+') as config_file: + config = json.load(config_file) + config["firstname"] = html_content["result"][0]["firstName"] + config["lastname"] = html_content["result"][0]["lastName"] + config["rating"] = str(html_content["result"][0]["rating"]), + config["contri"] = str(html_content["result"][0]["contribution"]), + config["rank"] = str(html_content["result"][0]["rank"]), + config["maxrating"] = str(html_content["result"][0]["maxRating"]) + config_file.seek(0) + config_file.truncate() + config_file.write(json.dumps(config)) + + def get_user(self): + config_file_path = self.config_file_path + with open(config_file_path, 'r') as config_file: + config = json.load(config_file) + user = { + "firstname":config["firstname"], + "lastname":config["lastname"], + "rating":config["rating"], + "contri":config["contri"], + "rank":config["rank"], + "maxrating":config["maxrating"] + } + return user \ No newline at end of file diff --git a/src/Config/config.json b/src/Config/config.json index b8d4b77..65360de 100644 --- a/src/Config/config.json +++ b/src/Config/config.json @@ -1 +1 @@ -{"test_in_progress": "False", "language": "python", "template": "D:\\Alok country\\Apun coder banega\\Projects\\CP-CLI\\test\\code.cpp", "proxy": ""} \ No newline at end of file +{"firstname": "", "lastname": "", "rating": "", "contri": "", "rank": "", "maxrating": "", "test_in_progress": "False", "language": "python", "template": "D:\\Alok country\\Apun coder banega\\Projects\\CP-CLI\\test\\code.cpp", "proxy": "edcguest:edcguest@172.31.100.27:3128"} \ No newline at end of file From 7c51d6b7c1b789cb7425c422625b33ef3d83ea4c Mon Sep 17 00:00:00 2001 From: ASHUTOSH <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Tue, 11 Oct 2022 21:41:19 +0530 Subject: [PATCH 03/22] made necessary changes to Config.py --- src/Config/Config.py | 22 +++++++--------------- src/Config/config.json | 2 +- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/Config/Config.py b/src/Config/Config.py index 440cc04..4789f43 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -98,12 +98,12 @@ def set_user(self, user): config_file_path = self.config_file_path with open(config_file_path, 'r+') as config_file: config = json.load(config_file) - config["firstname"] = html_content["result"][0]["firstName"] - config["lastname"] = html_content["result"][0]["lastName"] - config["rating"] = str(html_content["result"][0]["rating"]), - config["contri"] = str(html_content["result"][0]["contribution"]), - config["rank"] = str(html_content["result"][0]["rank"]), - config["maxrating"] = str(html_content["result"][0]["maxRating"]) + config["user"]["firstname"] = html_content["result"][0]["firstName"] + config["user"]["lastname"] = html_content["result"][0]["lastName"] + config["user"]["rating"] = str(html_content["result"][0]["rating"]), + config["user"]["contri"] = str(html_content["result"][0]["contribution"]), + config["user"]["rank"] = str(html_content["result"][0]["rank"]), + config["user"]["maxrating"] = str(html_content["result"][0]["maxRating"]) config_file.seek(0) config_file.truncate() config_file.write(json.dumps(config)) @@ -112,12 +112,4 @@ def get_user(self): config_file_path = self.config_file_path with open(config_file_path, 'r') as config_file: config = json.load(config_file) - user = { - "firstname":config["firstname"], - "lastname":config["lastname"], - "rating":config["rating"], - "contri":config["contri"], - "rank":config["rank"], - "maxrating":config["maxrating"] - } - return user \ No newline at end of file + return config["user"] \ No newline at end of file diff --git a/src/Config/config.json b/src/Config/config.json index 65360de..28549c4 100644 --- a/src/Config/config.json +++ b/src/Config/config.json @@ -1 +1 @@ -{"firstname": "", "lastname": "", "rating": "", "contri": "", "rank": "", "maxrating": "", "test_in_progress": "False", "language": "python", "template": "D:\\Alok country\\Apun coder banega\\Projects\\CP-CLI\\test\\code.cpp", "proxy": "edcguest:edcguest@172.31.100.27:3128"} \ No newline at end of file +{"user": {"firstname": "Gennady", "lastname": "Korotkevich", "rating": ["3834"], "contri": ["134"], "rank": ["legendary grandmaster"], "maxrating": "3979"}, "test_in_progress": "False", "language": "python", "template": "D:\\Alok country\\Apun coder banega\\Projects\\CP-CLI\\test\\code.cpp", "proxy": "edcguest:edcguest@172.31.100.27:3128"} \ No newline at end of file From bd767dc0a6e09c31afcc4680968b42b1226986a2 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Tue, 11 Oct 2022 21:42:50 +0530 Subject: [PATCH 04/22] Update config.json --- src/Config/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/config.json b/src/Config/config.json index 28549c4..51c57b6 100644 --- a/src/Config/config.json +++ b/src/Config/config.json @@ -1 +1 @@ -{"user": {"firstname": "Gennady", "lastname": "Korotkevich", "rating": ["3834"], "contri": ["134"], "rank": ["legendary grandmaster"], "maxrating": "3979"}, "test_in_progress": "False", "language": "python", "template": "D:\\Alok country\\Apun coder banega\\Projects\\CP-CLI\\test\\code.cpp", "proxy": "edcguest:edcguest@172.31.100.27:3128"} \ No newline at end of file +{"user": {"firstname": "", "lastname": "", "rating": [""], "contri": [""], "rank": [""], "maxrating": ""}, "test_in_progress": "False", "language": "python", "template": "D:\\Alok country\\Apun coder banega\\Projects\\CP-CLI\\test\\code.cpp", "proxy": ""} From 7bec9312e0bc32648095912b1791752d8fff20f9 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Tue, 11 Oct 2022 21:44:38 +0530 Subject: [PATCH 05/22] Update COMMANDS.md --- COMMANDS.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/COMMANDS.md b/COMMANDS.md index dcb19e6..3d3ac0b 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -21,20 +21,20 @@ Currently value of `` can only be 'python' or 'cpp' are supported * ``` - ecp config set_user + ecp config set-user ``` Example: ``` - ecp config get_user tourist + ecp config set-user tourist ``` This fetch info about the user from config.json file. * ``` - ecp config get_user + ecp config get-user ``` Example: ``` - ecp config get_user + ecp config get-user ``` This will add necessary info about the user to config.json file. @@ -85,4 +85,4 @@ * Get remaining time duration in a test using: ``` ecp test time - ``` \ No newline at end of file + ``` From 44c8c1b89733e4f59975b444eda6aff0c62ee636 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Wed, 12 Oct 2022 23:07:47 +0530 Subject: [PATCH 06/22] Update Config.py --- src/Config/Config.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Config/Config.py b/src/Config/Config.py index 4789f43..3e73bb9 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -91,7 +91,8 @@ def remove_proxy(self): config_file.write(json.dumps(config)) def set_user(self, user): - response = requests.get(url='http://codeforces.com/api/user.info?handles='+user,proxies=self.get_proxy()) + address='http://codeforces.com/api/user.info?handles='+user + response = requests.get(url=address,proxies=self.get_proxy()) if(response.status_code!=200): raise UsernameError('User not Found') html_content = response.json() @@ -112,4 +113,4 @@ def get_user(self): config_file_path = self.config_file_path with open(config_file_path, 'r') as config_file: config = json.load(config_file) - return config["user"] \ No newline at end of file + return config["user"] From a931d454cab6498698d6fe8d34ae53ad672f90e7 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Thu, 13 Oct 2022 19:31:30 +0530 Subject: [PATCH 07/22] Update Config.py --- src/Config/Config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/Config.py b/src/Config/Config.py index 3e73bb9..f81bfaf 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -94,7 +94,7 @@ def set_user(self, user): address='http://codeforces.com/api/user.info?handles='+user response = requests.get(url=address,proxies=self.get_proxy()) if(response.status_code!=200): - raise UsernameError('User not Found') + raise UsernameError('UsernameNotFound') html_content = response.json() config_file_path = self.config_file_path with open(config_file_path, 'r+') as config_file: From 985d9115d2061c1592fe79dd1b5b2e7bf8025997 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Thu, 13 Oct 2022 19:35:59 +0530 Subject: [PATCH 08/22] Update config.py --- src/Cli/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cli/config.py b/src/Cli/config.py index 6b51cbf..5711fc7 100644 --- a/src/Cli/config.py +++ b/src/Cli/config.py @@ -79,7 +79,7 @@ def set_user(user): def get_user(): try: config = Config() - config.get_user() + print(config.get_user()) except Exception as e: click.echo(e) @@ -89,4 +89,4 @@ def get_user(): config.add_command(set_proxy) config.add_command(remove_proxy) config.add_command(set_user) -config.add_command(get_user) \ No newline at end of file +config.add_command(get_user) From fb226bd932383c6e11fea6f0cf9e50dd73c04fd6 Mon Sep 17 00:00:00 2001 From: ASHUTOSH <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Fri, 14 Oct 2022 14:13:52 +0530 Subject: [PATCH 09/22] added correct implemenatation of exception --- src/Config/Config.py | 11 +++++++---- src/Config/config.json | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Config/Config.py b/src/Config/Config.py index f81bfaf..48b7a9b 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -7,6 +7,10 @@ ''' Class to manage config related commands ''' +class UsernameNotFound(Exception): + def __init__(self, msg): + super().__init__(self, msg) + class Config(): supported_lang = ['cpp', 'python', 'java'] @@ -91,10 +95,9 @@ def remove_proxy(self): config_file.write(json.dumps(config)) def set_user(self, user): - address='http://codeforces.com/api/user.info?handles='+user - response = requests.get(url=address,proxies=self.get_proxy()) + response = requests.get(url='http://codeforces.com/api/user.info?handles='+user,proxies=self.get_proxy()) if(response.status_code!=200): - raise UsernameError('UsernameNotFound') + raise UsernameNotFound('User not found') html_content = response.json() config_file_path = self.config_file_path with open(config_file_path, 'r+') as config_file: @@ -113,4 +116,4 @@ def get_user(self): config_file_path = self.config_file_path with open(config_file_path, 'r') as config_file: config = json.load(config_file) - return config["user"] + return config["user"] \ No newline at end of file diff --git a/src/Config/config.json b/src/Config/config.json index 51c57b6..b54284e 100644 --- a/src/Config/config.json +++ b/src/Config/config.json @@ -1 +1 @@ -{"user": {"firstname": "", "lastname": "", "rating": [""], "contri": [""], "rank": [""], "maxrating": ""}, "test_in_progress": "False", "language": "python", "template": "D:\\Alok country\\Apun coder banega\\Projects\\CP-CLI\\test\\code.cpp", "proxy": ""} +{"user": {"firstname": "", "lastname": "", "rating": [""], "contri": [""], "rank": [""], "maxrating": ""}, "test_in_progress": "False", "language": "python", "template": "D:\\Alok country\\Apun coder banega\\Projects\\CP-CLI\\test\\code.cpp", "proxy": ""} \ No newline at end of file From 7176f959a89ae3fb4a14945c124f8ff1a689b7ba Mon Sep 17 00:00:00 2001 From: ASHUTOSH <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Fri, 14 Oct 2022 22:29:22 +0530 Subject: [PATCH 10/22] organised exception in config.py --- src/Config/Config.py | 10 +++------- src/Config/exceptions/UserNotFound.py | 3 +++ src/Config/exceptions/__init__.py | 0 3 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 src/Config/exceptions/UserNotFound.py create mode 100644 src/Config/exceptions/__init__.py diff --git a/src/Config/Config.py b/src/Config/Config.py index 48b7a9b..58fbfb9 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -1,16 +1,13 @@ import json import os import requests +import click from pathlib import Path from ..Runner.exceptions.UnsupportedLanguage import UnsupportedLanguage - +from .exceptions.UserNotFound import UsernameNotFound ''' Class to manage config related commands ''' -class UsernameNotFound(Exception): - def __init__(self, msg): - super().__init__(self, msg) - class Config(): supported_lang = ['cpp', 'python', 'java'] @@ -97,7 +94,7 @@ def remove_proxy(self): def set_user(self, user): response = requests.get(url='http://codeforces.com/api/user.info?handles='+user,proxies=self.get_proxy()) if(response.status_code!=200): - raise UsernameNotFound('User not found') + raise UsernameNotFound() html_content = response.json() config_file_path = self.config_file_path with open(config_file_path, 'r+') as config_file: @@ -111,7 +108,6 @@ def set_user(self, user): config_file.seek(0) config_file.truncate() config_file.write(json.dumps(config)) - def get_user(self): config_file_path = self.config_file_path with open(config_file_path, 'r') as config_file: diff --git a/src/Config/exceptions/UserNotFound.py b/src/Config/exceptions/UserNotFound.py new file mode 100644 index 0000000..a000789 --- /dev/null +++ b/src/Config/exceptions/UserNotFound.py @@ -0,0 +1,3 @@ +class UsernameNotFound(Exception): + def __init__(self, msg="User not found"): + super().__init__(self, msg) \ No newline at end of file diff --git a/src/Config/exceptions/__init__.py b/src/Config/exceptions/__init__.py new file mode 100644 index 0000000..e69de29 From 51a66e91be0a62b03808d7518aea893f2103ad37 Mon Sep 17 00:00:00 2001 From: ASHUTOSH <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Sun, 16 Oct 2022 16:47:00 +0530 Subject: [PATCH 11/22] UserNotSet exception class created --- src/Config/Config.py | 3 +++ src/Config/exceptions/UserNotSet.py | 3 +++ 2 files changed, 6 insertions(+) create mode 100644 src/Config/exceptions/UserNotSet.py diff --git a/src/Config/Config.py b/src/Config/Config.py index 58fbfb9..d6270a9 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -5,6 +5,7 @@ from pathlib import Path from ..Runner.exceptions.UnsupportedLanguage import UnsupportedLanguage from .exceptions.UserNotFound import UsernameNotFound +from .exceptions.UserNotSet import UserNotSet ''' Class to manage config related commands ''' @@ -112,4 +113,6 @@ def get_user(self): config_file_path = self.config_file_path with open(config_file_path, 'r') as config_file: config = json.load(config_file) + if(len(config["user"]["firstname"])==0): + raise UserNotSet return config["user"] \ No newline at end of file diff --git a/src/Config/exceptions/UserNotSet.py b/src/Config/exceptions/UserNotSet.py new file mode 100644 index 0000000..c77ff83 --- /dev/null +++ b/src/Config/exceptions/UserNotSet.py @@ -0,0 +1,3 @@ +class UserNotSet(Exception): + def __init__(self, msg="User not set yet."): + super().__init__(self, msg) \ No newline at end of file From 1c10403cd4168ced1b3a4a7c83ae651eefd90fb8 Mon Sep 17 00:00:00 2001 From: ASHUTOSH <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Sun, 16 Oct 2022 20:46:11 +0530 Subject: [PATCH 12/22] api url varible formed --- src/Config/Config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Config/Config.py b/src/Config/Config.py index d6270a9..fdc6489 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -93,7 +93,8 @@ def remove_proxy(self): config_file.write(json.dumps(config)) def set_user(self, user): - response = requests.get(url='http://codeforces.com/api/user.info?handles='+user,proxies=self.get_proxy()) + api_url = 'http://codeforces.com/api/user.info?handles=' + response = requests.get(url=api_url+user,proxies=self.get_proxy()) if(response.status_code!=200): raise UsernameNotFound() html_content = response.json() From e51e8770a2149aaaa9fd4066384fa7c41ddd9783 Mon Sep 17 00:00:00 2001 From: ASHUTOSH <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Tue, 18 Oct 2022 19:37:06 +0530 Subject: [PATCH 13/22] modified UserNotSet.py and UserNotFound.py and fixed error HTTPSConnectionPool(host='codeforces.com', port=443): Max retries exceeded with url: /api/user.info?handles=touris (Caused by ProxyError('Your proxy appears to only use HTTP and not HTTPS, try changing your proxy URL to be HTTP. See: https://urllib3.readthedocs.io/en/1.26.x/advanced-usage.html#https-proxy-error-http-proxy', SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1129)')))) --- src/Config/Config.py | 18 ++++++++++-------- src/Config/exceptions/UserNotFound.py | 4 ++-- src/Config/exceptions/UserNotSet.py | 4 ++-- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/Config/Config.py b/src/Config/Config.py index fdc6489..da74846 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -6,6 +6,7 @@ from ..Runner.exceptions.UnsupportedLanguage import UnsupportedLanguage from .exceptions.UserNotFound import UsernameNotFound from .exceptions.UserNotSet import UserNotSet +from requests.adapters import HTTPAdapter, Retry ''' Class to manage config related commands ''' @@ -79,9 +80,9 @@ def get_proxy(self): config = json.load(config_file) proxy = config['proxy'] if len(proxy)==0: - proxy = {'http':None,'https':None} + proxy = {'http':None} else: - proxy = {'http':'http://'+proxy,'https':'https://'+proxy} + proxy = {'http':'http://'+proxy} return proxy def remove_proxy(self): @@ -93,10 +94,10 @@ def remove_proxy(self): config_file.write(json.dumps(config)) def set_user(self, user): - api_url = 'http://codeforces.com/api/user.info?handles=' - response = requests.get(url=api_url+user,proxies=self.get_proxy()) - if(response.status_code!=200): - raise UsernameNotFound() + api_url = "https://codeforces.com/api/user.info?handles=" + response = requests.get(url=api_url + user, proxies = self.get_proxy()) + if(response.status_code != 200): + raise UsernameNotFound(user) html_content = response.json() config_file_path = self.config_file_path with open(config_file_path, 'r+') as config_file: @@ -110,10 +111,11 @@ def set_user(self, user): config_file.seek(0) config_file.truncate() config_file.write(json.dumps(config)) + def get_user(self): config_file_path = self.config_file_path with open(config_file_path, 'r') as config_file: config = json.load(config_file) - if(len(config["user"]["firstname"])==0): - raise UserNotSet + if(len(config["user"]["firstname"]) == 0): + raise UserNotSet() return config["user"] \ No newline at end of file diff --git a/src/Config/exceptions/UserNotFound.py b/src/Config/exceptions/UserNotFound.py index a000789..0f31178 100644 --- a/src/Config/exceptions/UserNotFound.py +++ b/src/Config/exceptions/UserNotFound.py @@ -1,3 +1,3 @@ class UsernameNotFound(Exception): - def __init__(self, msg="User not found"): - super().__init__(self, msg) \ No newline at end of file + def __init__(self, userName) -> None: + super().__init__(f'{userName} not found.') \ No newline at end of file diff --git a/src/Config/exceptions/UserNotSet.py b/src/Config/exceptions/UserNotSet.py index c77ff83..1770ab2 100644 --- a/src/Config/exceptions/UserNotSet.py +++ b/src/Config/exceptions/UserNotSet.py @@ -1,3 +1,3 @@ class UserNotSet(Exception): - def __init__(self, msg="User not set yet."): - super().__init__(self, msg) \ No newline at end of file + def __init__(self) -> None: + super().__init__("User not set yet.") \ No newline at end of file From 6443bb69f402566b4cb9a28e9caf5024346ee962 Mon Sep 17 00:00:00 2001 From: ASHUTOSH <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Tue, 18 Oct 2022 23:52:17 +0530 Subject: [PATCH 14/22] fixed the error on no proxy reference : https://stackoverflow.com/questions/28521535/requests-how-to-disable-bypass-proxy --- src/Config/Config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Config/Config.py b/src/Config/Config.py index da74846..f542104 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -80,7 +80,7 @@ def get_proxy(self): config = json.load(config_file) proxy = config['proxy'] if len(proxy)==0: - proxy = {'http':None} + proxy = {'http':'','https':''} else: proxy = {'http':'http://'+proxy} return proxy @@ -95,7 +95,7 @@ def remove_proxy(self): def set_user(self, user): api_url = "https://codeforces.com/api/user.info?handles=" - response = requests.get(url=api_url + user, proxies = self.get_proxy()) + response = requests.get(url = api_url + user, proxies = self.get_proxy()) if(response.status_code != 200): raise UsernameNotFound(user) html_content = response.json() From bdd40d8ae93ede820d87ed93221277646f1d5e38 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Thu, 20 Oct 2022 20:12:59 +0530 Subject: [PATCH 15/22] Update UserNotSet.py --- src/Config/exceptions/UserNotSet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/exceptions/UserNotSet.py b/src/Config/exceptions/UserNotSet.py index 1770ab2..75ba67c 100644 --- a/src/Config/exceptions/UserNotSet.py +++ b/src/Config/exceptions/UserNotSet.py @@ -1,3 +1,3 @@ class UserNotSet(Exception): def __init__(self) -> None: - super().__init__("User not set yet.") \ No newline at end of file + super().__init__("User not set yet") From 5bf67edef19575d0aa1ad906dfc2ee6f9cca5718 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Thu, 20 Oct 2022 20:19:13 +0530 Subject: [PATCH 16/22] Update config.py --- src/Cli/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Cli/config.py b/src/Cli/config.py index 5711fc7..3c3cab0 100644 --- a/src/Cli/config.py +++ b/src/Cli/config.py @@ -74,14 +74,14 @@ def set_user(user): config.set_user(user) click.echo(click.style('User information have been fetched.', fg='green')) except Exception as e: - click.echo(e) + click.echo(click.style(e,fg='red')) @click.command() def get_user(): try: config = Config() print(config.get_user()) except Exception as e: - click.echo(e) + click.echo(click.style(e,fg='red')) config.add_command(get_lang) config.add_command(set_lang) From d06f904b38e49ab24ac0b0819191ed7c7b7c0d5b Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Thu, 20 Oct 2022 20:21:20 +0530 Subject: [PATCH 17/22] Update config.py --- src/Cli/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/config.py b/src/Cli/config.py index 3c3cab0..15f622c 100644 --- a/src/Cli/config.py +++ b/src/Cli/config.py @@ -79,7 +79,7 @@ def set_user(user): def get_user(): try: config = Config() - print(config.get_user()) + click.echo(config.get_user()) except Exception as e: click.echo(click.style(e,fg='red')) From 993c76ff5adad1f322f139f15559c85705fd5959 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Fri, 21 Oct 2022 23:23:37 +0530 Subject: [PATCH 18/22] Update Config.py --- src/Config/Config.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Config/Config.py b/src/Config/Config.py index f542104..84ef49e 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -104,9 +104,9 @@ def set_user(self, user): config = json.load(config_file) config["user"]["firstname"] = html_content["result"][0]["firstName"] config["user"]["lastname"] = html_content["result"][0]["lastName"] - config["user"]["rating"] = str(html_content["result"][0]["rating"]), - config["user"]["contri"] = str(html_content["result"][0]["contribution"]), - config["user"]["rank"] = str(html_content["result"][0]["rank"]), + config["user"]["rating"] = str(html_content["result"][0]["rating"]) + config["user"]["contri"] = str(html_content["result"][0]["contribution"]) + config["user"]["rank"] = str(html_content["result"][0]["rank"]) config["user"]["maxrating"] = str(html_content["result"][0]["maxRating"]) config_file.seek(0) config_file.truncate() @@ -118,4 +118,4 @@ def get_user(self): config = json.load(config_file) if(len(config["user"]["firstname"]) == 0): raise UserNotSet() - return config["user"] \ No newline at end of file + return config["user"] From c44e8d58c1aa107c8cef8eb6990fc7da92636844 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Fri, 21 Oct 2022 23:33:09 +0530 Subject: [PATCH 19/22] Update Config.py --- src/Config/Config.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Config/Config.py b/src/Config/Config.py index 84ef49e..d9ed9dc 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -104,10 +104,10 @@ def set_user(self, user): config = json.load(config_file) config["user"]["firstname"] = html_content["result"][0]["firstName"] config["user"]["lastname"] = html_content["result"][0]["lastName"] - config["user"]["rating"] = str(html_content["result"][0]["rating"]) - config["user"]["contri"] = str(html_content["result"][0]["contribution"]) - config["user"]["rank"] = str(html_content["result"][0]["rank"]) - config["user"]["maxrating"] = str(html_content["result"][0]["maxRating"]) + config["user"]["rating"] = html_content["result"][0]["rating"] + config["user"]["contri"] = html_content["result"][0]["contribution"] + config["user"]["rank"] = html_content["result"][0]["rank"] + config["user"]["maxrating"] = html_content["result"][0]["maxRating"] config_file.seek(0) config_file.truncate() config_file.write(json.dumps(config)) From c029516aef2d30d0e560e5c7bfc7e2dc9ec9398a Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Fri, 21 Oct 2022 23:34:03 +0530 Subject: [PATCH 20/22] Update config.json --- src/Config/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Config/config.json b/src/Config/config.json index b54284e..4b69692 100644 --- a/src/Config/config.json +++ b/src/Config/config.json @@ -1 +1 @@ -{"user": {"firstname": "", "lastname": "", "rating": [""], "contri": [""], "rank": [""], "maxrating": ""}, "test_in_progress": "False", "language": "python", "template": "D:\\Alok country\\Apun coder banega\\Projects\\CP-CLI\\test\\code.cpp", "proxy": ""} \ No newline at end of file +{"user": {"firstname": "", "lastname": "", "rating": "", "contri": "", "rank": "", "maxrating": ""}, "test_in_progress": "False", "language": "python", "template": "D:\\Alok country\\Apun coder banega\\Projects\\CP-CLI\\test\\code.cpp", "proxy": ""} From a12898ed38cd176403c16d79a7629ebe4a3bc5e8 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Sat, 22 Oct 2022 13:41:35 +0530 Subject: [PATCH 21/22] Update Config.py --- src/Config/Config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Config/Config.py b/src/Config/Config.py index d9ed9dc..794e9e1 100644 --- a/src/Config/Config.py +++ b/src/Config/Config.py @@ -118,4 +118,5 @@ def get_user(self): config = json.load(config_file) if(len(config["user"]["firstname"]) == 0): raise UserNotSet() - return config["user"] + for info in config["user"]: + print(info + " : " + str(config["user"][info])) From 22a768f95982f2df31786ada7c5f713e014ed986 Mon Sep 17 00:00:00 2001 From: Ashu <77433155+ashutoshsuthar2020@users.noreply.github.com> Date: Sat, 22 Oct 2022 13:42:22 +0530 Subject: [PATCH 22/22] Update config.py --- src/Cli/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/config.py b/src/Cli/config.py index 15f622c..63f6f8f 100644 --- a/src/Cli/config.py +++ b/src/Cli/config.py @@ -79,7 +79,7 @@ def set_user(user): def get_user(): try: config = Config() - click.echo(config.get_user()) + config.get_user() except Exception as e: click.echo(click.style(e,fg='red'))