-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
90 lines (80 loc) · 3.35 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import sys
import os
from selenium.webdriver.common.by import By
sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
from FUNC_LIBRARY import autoLogin
from ESSENTIAL_FILES import manage
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from EXECUTION_FILE import RUN_DRAFT
def set_chromedriver():
options = webdriver.ChromeOptions() # 크롬 옵션 객체 생성
options.add_argument("disable-gpu")
try:
# 로컬 크롬 드라이버 확인
chrome_driver_root_path = os.path.abspath("./chromedriver.exe")
# print(chrome_driver_root_path)
service = Service(chrome_driver_root_path)
# 'C:/Users/kyh57/python_proj/HAMA-system'
if not os.path.exists(chrome_driver_root_path):
raise FileNotFoundError(f"ChromeDriver not found at {chrome_driver_root_path}")
return webdriver.Chrome(service=service, options=options)
except Exception as e:
print("예외가 발생했습니다:", str(e))
print("크롬드라이버 실행에 실패했습니다. 외부 크롬드라이버를 다운로드 합니다.")
try:
# 없으면 인스톨
return webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
except Exception as e2:
print("예외가 발생했습니다:", str(e2))
print("외부 크롬드라이버 다운로드에 실패했습니다. 프로그램을 종료합니다.")
raise e2
if __name__ == '__main__':
# start = time.time()
try:
driver = set_chromedriver()
except Exception as ex:
print(ex)
input()
driver = set_chromedriver()
driver.implicitly_wait(time_to_wait=5)
# print(time.time()-start)
driver.get("https://www.hongik.ac.kr/login.do?Refer=https://ngw.hongik.ac.kr/login_hongik.aspx")
driver = autoLogin.login(driver)
#### only printing option ####
# dr = True
dr = False
if dr:
while True:
RUN_DRAFT.draft(driver)
while True:
# select = '조회'
# select = '작성'
# select = '수정'
select = '기안'
# select = '출근'
# select = '종료'
if select == '조회':
driver = autoLogin.afterLogin(driver)
manage.lookup(driver)
elif select == '작성':
driver.get('https://itss.hongik.ac.kr/GateWeb/index.aspx')
driver.execute_script("fclick(arguments[0])",
driver.find_element(By.ID, "d4_AHG020P").find_element(By.TAG_NAME, "span"))
manage.write(driver)
elif select == '수정':
driver = autoLogin.afterLogin(driver)
manage.modify(driver, False)
elif select == '기안':
driver.get('https://itss.hongik.ac.kr/GateWeb/index.aspx')
autoLogin.checkUpdatePasswordAlert(driver)
driver.execute_script("fclick(arguments[0])",
driver.find_element(By.ID, "d4_AHG029S").find_element(By.TAG_NAME, "span"))
RUN_DRAFT.draft_write(driver)
elif select == '출근':
driver = autoLogin.checkWork(driver)
elif select == '종료':
break
# else:
# print("잘못된 입력입니다.")