Skip to content

Commit

Permalink
Update - auto class works now
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyGroupHub committed Feb 20, 2023
1 parent 265be25 commit bb50666
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
25 changes: 20 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""This python file will do the AutoClass job."""
import time

from selenium import webdriver
from selenium.common import TimeoutException
Expand Down Expand Up @@ -38,7 +37,23 @@ def login():
except TimeoutException:
print("Login Failed, relog now.")
login()


login()
time.sleep(100)
auto_class(config.get("class_ids"))


def auto_class(class_ids):
driver_click((By.ID, "ctl00_MainContent_TabContainer1_tabSelected_Label3"))
for class_id in class_ids:
driver_send_keys((By.ID, "ctl00_MainContent_TabContainer1_tabSelected_tbSubID"), class_id)
try:
WebDriverWait(driver, 0.5).until(ec.presence_of_element_located((By.ID,
"//*[@id='ctl00_MainContent_TabContainer1_tabSelected_gvToDel']/tbody/tr[2]/td[1]/input")))
class_ids.remove(class_id)
except TimeoutException:
driver_click((By.XPATH,
"//*[@id='ctl00_MainContent_TabContainer1_tabSelected_gvToAdd']/tbody/tr[2]/td[1]/input"))
auto_class(class_ids)


if __name__ == "__main__":
login()
driver.quit()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PyYAML==6.0
selenium~=4.8.0
selenium==4.8.2
ddddocr~=1.4.7
19 changes: 18 additions & 1 deletion utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ def config_file_generator():
# FCU Account
username: ''
password: ''
# Class to join
# If you have more than one class to join, please separate them with space.
# Example: class_id: '0050 0051'
# The less class_id you have, the more rate you can get the class you want.
class_id: ''
"""
)
sys.exit()
Expand All @@ -39,9 +45,11 @@ def read_config():
try:
with open('config.yml', 'r', encoding="utf8") as f:
data = yaml.load(f, Loader=SafeLoader)
class_ids = get_class_ids(data['class_id'])
config = {
'username': data['username'],
'password': data['password']
'password': data['password'],
'class_ids': class_ids
}
return config
except (KeyError, TypeError):
Expand All @@ -51,6 +59,15 @@ def read_config():
sys.exit()


def get_class_ids(class_id):
"""Read class_id from config file.
:rtype: list
"""
class_ids = class_id.split(" ")
return class_ids


def get_ocr_answer(ocr_image_path):
"""Get the answer of ocr.
Expand Down

0 comments on commit bb50666

Please sign in to comment.