├── README.md ├── automate.py ├── automate.sublime-build └── contest.py /README.md: -------------------------------------------------------------------------------- 1 | # AutomateOlympicCoding 2 | I made a **Test Case Parser** and it can parse test cases for your problem in just one keystroke. 3 | 4 | **Update** : **Contest Parser** was also added 5 | 6 | Download the github repo from here : [AutomateOlympicCoding](https://github.com/epsilon573/AutomateOlympicCoding). 7 | 8 | #### Video Walkthrough 9 | - [Youtube](https://www.youtube.com/watch?v=gg1cwWMnLhc) 10 | 11 | ### How to Setup : 12 | 13 | Video Walkthrough just explains parsing test cases for a single problem. Contest Parser was added later. 14 | 15 | - Install all the required dependencies. 16 | - Clone the github repo 17 | - Place the build file in Packages->User 18 | - Place automate.py and contest.py in the same folder as your main cpp solution file 19 | - In the latest version you don't need to rename anything, it will generate test cases with the same name as your working file 20 | 21 | #### Parsing single problem : 22 | 23 | - Open your cpp solution file ( must be in the same directory as automate and contest.py ) 24 | - Open the problem page on Chrome ( only works on chrome ) 25 | - Open sublime text and build using automate build system ( Ctrl + Shift + B) 26 | - This plugin will create a test file with the same name as your solution file 27 | - Now just run your solution using FastOlympicCoding 28 | 29 | #### Parsing a complete contest : 30 | 31 | - Create a template.cpp file ( must be in the same directory as automate and contest.py ) . 32 | - This file will be copied to all solution files when parsing the contest 33 | - Open any cpp file in the same directory ( preferably template.cpp ) 34 | - Open the contest page on Chrome ( only works on chrome ) 35 | - Open sublime text and build using automate-contest build system ( Ctrl + Shift + B) 36 | - This plugin will create a directory with the contest ID and it will contain cpp files for all problems with template copied into them and corresponding test files will be parsed with them. 37 | - Just open them and start solving. 38 | - Now just run your solution using FastOlympicCoding 39 | 40 | ### Dependencies : 41 | 42 | - Install Python3. 43 | - pip install bs4 44 | - pip install pywinauto 45 | 46 | You can support me on my Youtube Channel here : [GGxEpsilon](https://www.youtube.com/c/GGxEpsilon) 47 | 48 | Support for more platforms like CodeChef and Atcoder will be added soon. 49 | 50 | Thanks for reading and feedback will be appreciated. 51 | -------------------------------------------------------------------------------- /automate.py: -------------------------------------------------------------------------------- 1 | import json 2 | import urllib.request 3 | from bs4 import BeautifulSoup 4 | from pywinauto import Application 5 | import os 6 | import sys 7 | 8 | if(len(sys.argv)==1): 9 | app = Application(backend='uia') 10 | app.connect(title_re=".*Chrome.*") 11 | dlg = app.top_window() 12 | url = dlg.child_window(title="Address and search bar", control_type="Edit").get_value() 13 | url = "https://" + url 14 | filename = "solution.cpp__tests" 15 | elif(len(sys.argv)==2): 16 | app = Application(backend='uia') 17 | app.connect(title_re=".*Chrome.*") 18 | dlg = app.top_window() 19 | url = dlg.child_window(title="Address and search bar", control_type="Edit").get_value() 20 | url = "https://" + url 21 | filename = sys.argv[1] + "__tests" 22 | else: 23 | url = sys.argv[1] 24 | filename = sys.argv[2] + ".cpp__tests" 25 | 26 | if( url.find('https://codeforces.com/') == -1): 27 | with open("solution.cpp__tests", "w") as outfile: 28 | outfile.write('Please open a problem page') 29 | exit() 30 | else: 31 | try: 32 | page = urllib.request.urlopen(url) 33 | except: 34 | print(url) 35 | exit() 36 | soup = BeautifulSoup(page, features = "html.parser") 37 | 38 | x = soup.body.find_all('div', attrs={'class' : 'input'}) 39 | y = soup.body.find_all('div', attrs={'class' : 'output'}) 40 | 41 | res = "" 42 | out = "" 43 | 44 | for elements in x: 45 | for br in elements.find_all("br"): 46 | br.replace_with("\n") 47 | res += elements.text 48 | for elements in y: 49 | out += elements.text 50 | 51 | if 'Input\n' in res: 52 | res = res.split('Input\n') 53 | else: 54 | res = res.split('Input') 55 | 56 | if 'Output\n' in out: 57 | out = out.split('Output\n') 58 | else: 59 | out = out.split('Output') 60 | 61 | res.remove("") 62 | out.remove("") 63 | 64 | #res = [elements.strip() for elements in res] 65 | out = [elements.strip() for elements in out] 66 | 67 | correct = [] 68 | for elements in out: 69 | correct.append([elements]) 70 | 71 | final = [] 72 | sz = len(res) 73 | 74 | for i in range(sz): 75 | dic = { 76 | "correct_answers" : correct[i], 77 | "test" : res[i] 78 | } 79 | final.append(dic) 80 | 81 | 82 | with open(filename, "w") as outfile: 83 | outfile.write(json.dumps(final)) 84 | -------------------------------------------------------------------------------- /automate.sublime-build: -------------------------------------------------------------------------------- 1 | { 2 | "cmd": ["python", "automate.py", "$file_name"], 3 | "selector": "source.c++", 4 | "file_regex": "^\\s*File \"(...*?)\", line ([0-9]*)", 5 | 6 | "variants": 7 | [ 8 | { 9 | "name": "Contest", 10 | "cmd": ["python", "contest.py"] 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /contest.py: -------------------------------------------------------------------------------- 1 | import json 2 | import urllib.request 3 | from bs4 import BeautifulSoup 4 | from pywinauto import Application 5 | import os 6 | 7 | app = Application(backend='uia') 8 | app.connect(title_re=".*Chrome.*") 9 | dlg = app.top_window() 10 | url = dlg.child_window(title="Address and search bar", control_type="Edit").get_value() 11 | 12 | url = "https://" + url 13 | if( url.find('https://codeforces.com/contest') == -1): 14 | with open("solution.cpp__tests", "w") as outfile: 15 | outfile.write('Please open a contest page') 16 | exit() 17 | else: 18 | page = urllib.request.urlopen(url) 19 | soup = BeautifulSoup(page, features = "html.parser") 20 | 21 | data = [] 22 | 23 | table = soup.find('table', attrs={'class':'problems'}) 24 | 25 | rows = table.find_all('tr') 26 | for row in rows: 27 | cols = row.find_all('td') 28 | cols = [ele.text.strip() for ele in cols] 29 | data.append([ele for ele in cols if ele]) 30 | 31 | problem_tags = [] 32 | for i in range(len(data)): 33 | if(len(data[i])>0): 34 | problem_tags.append(data[i][0]) 35 | 36 | print(problem_tags) 37 | 38 | contest_id = url[-4] + url[-3] + url[-2] + url[-1] 39 | path = contest_id 40 | parent_dir = os.getcwd() 41 | 42 | path = os.path.join(parent_dir,path) 43 | if not os.path.exists(path): 44 | os.mkdir(path) 45 | 46 | for problems in problem_tags: 47 | problem_path = os.path.join(path,problems) 48 | print(problem_path) 49 | with open("template.cpp") as main: 50 | with open(problem_path+".cpp", "w") as sec: 51 | for line in main: 52 | sec.write(line) 53 | problem_url = " " + url + "/problem/" + problems + " \""; 54 | os.system('python automate.py' + problem_url + problem_path + "\"") 55 | --------------------------------------------------------------------------------