├── docs ├── index.md ├── _config.yml └── zipball │ └── main.zip ├── validate.py ├── .gitignore ├── db.py └── main.py /docs/index.md: -------------------------------------------------------------------------------- 1 | # Hi 2 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-minimal -------------------------------------------------------------------------------- /docs/zipball/main.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baruchiro/halomda/master/docs/zipball/main.zip -------------------------------------------------------------------------------- /validate.py: -------------------------------------------------------------------------------- 1 | import pandas as pd 2 | import os 3 | df = pd.read_csv(os.getcwd() + "/db.csv") 4 | x = 5 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | geckodriver.log 2 | chromedriver 3 | .vscode/ 4 | db.csv 5 | 6 | __pycache__/ 7 | 8 | # pyinstaller 9 | build/ 10 | dist/ 11 | *.spec 12 | -------------------------------------------------------------------------------- /db.py: -------------------------------------------------------------------------------- 1 | import os 2 | import csv 3 | 4 | file = 'db.csv' 5 | data = {} 6 | 7 | if os.path.isfile(file): 8 | with open(file) as f: 9 | reader = csv.reader(f) 10 | data = {l[0]: l[1:] for l in list(reader)} 11 | print(f'file {file} exist with {len(data)} rows') 12 | 13 | else: 14 | print(f'file {file} not exist') 15 | 16 | 17 | def tryGet(question): 18 | question = question[24:] 19 | res = data.get(question) 20 | if res: 21 | res = res[0] 22 | return res 23 | 24 | 25 | def add(question, answer, work, section, task): 26 | question = question[24:] 27 | if question not in data or input("The answer exist, are you sure? y/n")[0].lower() == 'y': 28 | data[question] = [answer, work, section, task] 29 | save() 30 | 31 | 32 | def save(): 33 | with open(file, 'w+') as f: 34 | f.write('\n'.join([k+','+','.join(v) for k, v in data.items()])) 35 | print(f'{len(data)} lines writed to {file}') 36 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from selenium import webdriver 3 | from selenium.webdriver.common.by import By 4 | from selenium.webdriver.common.keys import Keys 5 | from selenium.webdriver.support.ui import Select 6 | from selenium.common.exceptions import NoSuchElementException 7 | from selenium.common.exceptions import NoAlertPresentException 8 | import unittest 9 | import time 10 | import re 11 | from bs4 import BeautifulSoup 12 | import db 13 | import sys 14 | 15 | rights = ["תשובה נכונה", "נכון!", "תוצאה נכונה", "בוצעה", "בוצע"] 16 | 17 | 18 | def parseWorks(tableHTML): 19 | soup = BeautifulSoup(tableHTML, "html.parser") 20 | menu = {} 21 | i = 1 22 | print("Select work:") 23 | for tr in soup.find_all('tr'): 24 | tds = tr.find_all('td') 25 | if len(tds) > 0: 26 | print(f'{i}. for {tds[0].get_text()[::-1]}') 27 | menu[i] = tds[0].find('a')['href'], tds[0].get_text() 28 | i = i + 1 29 | select = int(input("Your choice:")) 30 | return menu[select] 31 | 32 | 33 | def parseTirgul(tableHTML): 34 | soup = BeautifulSoup(tableHTML, "html.parser") 35 | menu = {} 36 | i = 1 37 | print("Select train:") 38 | for tr in soup.find_all('tr'): 39 | tds = tr.find_all('td') 40 | if len(tds) > 0: 41 | print(f'{i}. for {tds[0].get_text()[::-1]}') 42 | menu[i] = tds[2].find('a')['href'], tds[0].get_text() 43 | i = i + 1 44 | #select = int(input("Your choice:")) 45 | return menu # [select] 46 | 47 | 48 | def parseTrainNum(tableHTML) -> dict: 49 | soup = BeautifulSoup(tableHTML, "html.parser") 50 | menu = {} 51 | i = 1 52 | print("Select train num:") 53 | for tr in soup.find_all('tr'): 54 | tds = tr.find_all('td') 55 | if len(tds) > 0: 56 | print(f'{i}. for {tds[0].get_text()[::-1]}') 57 | menu[i] = tds[0].find('a')['href'], tds[0].get_text() 58 | i = i + 1 59 | #select = int(input("Your choice:")) 60 | return menu # [select] 61 | 62 | 63 | def parseHints(table): 64 | soup = BeautifulSoup(table, "html.parser") 65 | return [img['onclick'] for img in soup.find_all('img')] 66 | 67 | 68 | def getQuestion(html): 69 | soup = BeautifulSoup(html, 'html.parser') 70 | return soup.find('img')['src'] 71 | 72 | 73 | def specificTask(driver, work, section, task): 74 | success = False 75 | question = getQuestion(driver.find_element_by_id( 76 | "Question").get_attribute('outerHTML')) 77 | answer = db.tryGet(question) 78 | if not answer: 79 | # Get Question 80 | driver.execute_script("HintBtnClick()") 81 | results = parseHints(driver.find_element_by_id( 82 | "HintsTable").get_attribute('outerHTML')) 83 | for ans in results: 84 | 85 | driver.execute_script(ans) 86 | driver.execute_script("event = {keyCode:13};KeyDownEvent(event);") 87 | 88 | text = driver.find_element_by_id( 89 | "OutWindow").get_attribute('innerText') 90 | success = any(x in text for x in rights) 91 | 92 | if success: 93 | db.add(question, ans, work, section, task) 94 | return question 95 | 96 | return None 97 | 98 | 99 | def workAgainstQuestion(driver, work, section, task): 100 | counter = 0 101 | 102 | while counter < 5: 103 | res = specificTask(driver, work, section, task) 104 | if res: 105 | counter = 0 106 | else: 107 | counter = counter + 1 108 | print(counter) 109 | 110 | driver.refresh() 111 | 112 | 113 | def main(): 114 | username = input("Enter user name (id number):") 115 | password = input("Enter user name (id number):") 116 | try: 117 | # Init 118 | driver = webdriver.Chrome(executable_path="./chromedriver.exe") 119 | driver.implicitly_wait(30) 120 | base_url = "https://halomda.org/" 121 | verificationErrors = [] 122 | accept_next_alert = True 123 | 124 | while True: 125 | # Login 126 | driver.get( 127 | "https://halomda.org/TestingDriverMy/WelcomeGuest-MichlalaWeb.php") 128 | driver.find_element_by_id("UserName").clear() 129 | driver.find_element_by_id("UserName").send_keys(username) 130 | driver.find_element_by_id("PassWord").clear() 131 | driver.find_element_by_id("PassWord").send_keys(password) 132 | driver.find_element_by_id("SubmitBtn").click() 133 | 134 | # Select work 135 | path, work = parseWorks(driver.find_element_by_xpath( 136 | "//table").get_attribute('outerHTML')) 137 | driver.get("https://halomda.org/" + path) 138 | 139 | # Select Section 140 | sections = parseTirgul(driver.find_element_by_xpath( 141 | "//table").get_attribute('outerHTML')) 142 | for section in sections.values(): 143 | print(f'------{section[1][::-1]}----------') 144 | driver.get("https://halomda.org/" + section[0]) 145 | 146 | # Select Task 147 | tasks = parseTrainNum(driver.find_element_by_xpath( 148 | "//table").get_attribute('outerHTML')) 149 | for task in tasks.values(): 150 | print(f'------{task[1][::-1]}----------') 151 | driver.get("https://halomda.org/" + task[0]) 152 | 153 | # We are in train! 154 | workAgainstQuestion(driver, work, section[1], task[1]) 155 | except Exception as e: 156 | print(e) 157 | finally: 158 | input("end, press enter") 159 | driver.close() 160 | db.save() 161 | 162 | 163 | if __name__ == "__main__": 164 | main() 165 | --------------------------------------------------------------------------------