Seleniumによる週次作業レポートの自動化


うちの会社はGoogle DogsとWekiページで毎週の仕事報告書を2回書いています.
これは面倒な仕事で、同じ内容を2回書きます.
そこで、Seleniumを利用してGoogle Dogで作成した毎週作業レポートをtxtにダウンロードし、ウィキページ上で自動的に生成されるプログラムを作成しました.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

def wirteFunc(target, StrNum, gubun, weekStrNum):
    if gubun == "예외":
        where = driver.find_element_by_css_selector(
            f'#tinymce > table > tbody > tr:nth-child(8) > td:nth-child({weekStrNum}) > ol > li:nth-child({StrNum})')
    else:
        where = driver.find_element_by_css_selector(
            f'#tinymce > table > tbody > tr:nth-child(8) > td:nth-child({weekStrNum}) > ol > li:nth-child({StrNum}) > p')
    where.click()

    for i, row in enumerate(target):
        temp = row.split('\n')[0]
        if not gubun == '':
            if temp[:2] in 모듈종류:
                where.send_keys(Keys.RETURN)
                if i == 0:
                    where.send_keys(Keys.TAB)
                where.send_keys('[' + Keys.TAB + temp[:2] + '[]')
                where.send_keys(Keys.ARROW_LEFT)
                where.send_keys(Keys.BACKSPACE)
                where.send_keys(Keys.ARROW_RIGHT)
                where.send_keys(temp[3:])
        else:
            where.send_keys(Keys.RETURN)
            if i == 0:
                where.send_keys(Keys.TAB)
            where.send_keys(temp)

    # tinymce > table > tbody > tr:nth-child(8) > td:nth-child(3) > ol > li:nth-child(1) > ol > li
    for i, row in enumerate(target):
        if len(target) - 1 == i:
            row = row.replace('\n\n', '')
        temp = row.split('\n')
        where = driver.find_element_by_css_selector(
            f'#tinymce > table > tbody > tr:nth-child(8) > td:nth-child({weekStrNum}) > ol > li:nth-child({StrNum}) > ol > li:nth-child({str(i + 1)})')
        where.click()
        where.send_keys(Keys.RETURN)
        where.send_keys(Keys.TAB)
        for q, text in enumerate(temp[1:]):
            if ')' not in text:
                if q != 0:
                    where.send_keys(Keys.RETURN)
                where.send_keys(text)

# path = input('변환할 주간업무보고 파일 경로를 입력하세요(.txt) : ')
# name = input('이름을 입력하세요 : ')
# url = input('작성할 위키페이지 url 주소를 입력하세요 : ')

options = Options()
options.add_argument('--kiosk')

모듈종류 = ['개인', '법인', '회계', '급여']
f = open(r'/Users/tyflow/Downloads/주간업무보고_서비스개발1센터_개발2Unit_개발1Cell_2021.txt')
# f = open(path)

text = f.read()
tempList = text.split(f'유정수\n1. SmartAX 개발 및 유지보수')
# tempList = text.split(f'{name}\n1. SmartAX 개발 및 유지보수')
section = tempList[1].split('(')
이번주_유지보수 = section[2].split('[')[2:] if '없습니다' not in section[2] else []
이번주_신규메뉴 = section[3].split('[')[1:] if '없습니다' not in section[3] else []
이번주_기타업무 = section[4].split(')')[2:] if '없습니다' not in section[4] else []
이번주_속도개선 = section[5].split('[')[1:] if '없습니다' not in section[5] else []
이번주_이슈사항 = section[6].split('[')[1:] if '없습니다' not in section[6] else []

section_next = tempList[1].split('1. SmartAX 개발 및 유지')[1].split('(')

다음주_유지보수 = section_next[1].split('[')[2:] if '없습니다' not in section_next[1] else []
다음주_신규메뉴 = section_next[2].split('[')[1:] if '없습니다' not in section_next[2] else []
다음주_기타업무 = section_next[3].split(')')[2:] if '없습니다' not in section_next[3] else []
다음주_속도개선 = section_next[4].split('[')[1:] if '없습니다' not in section_next[4] else []
다음주_이슈사항 = section_next[5].split('[')[1:] if '없습니다' not in section_next[5] else []

driver = webdriver.Chrome('/Users/tyflow/Downloads/chromedriver', chrome_options=options)
url = 'http://wiki.duzon.com:8080/pages/editpage.action?pageId=101561528'
driver.get(url)

rogIn = driver.find_element_by_xpath('//*[@id="os_username"]')
rogIn.send_keys('jshi25')
rogIn = driver.find_element_by_xpath('//*[@id="os_password"]')
rogIn.send_keys('jshi25')
rogIn.send_keys(Keys.RETURN)

driver.switch_to.frame("wysiwygTextarea_ifr")
now = '2'
wirteFunc(이번주_유지보수, '1', '모듈', now)
wirteFunc(이번주_신규메뉴, '2', '모듈', now)
wirteFunc(이번주_기타업무, '3', '', now)
wirteFunc(이번주_속도개선, '4', '예외', now)
wirteFunc(이번주_이슈사항, '5', '예외', now)

next = '3'
wirteFunc(다음주_유지보수, '1', '예외', next)
wirteFunc(다음주_신규메뉴, '2', '예외', next)
wirteFunc(다음주_기타업무, '3', '예외', next)
wirteFunc(다음주_속도개선, '4', '예외', next)
wirteFunc(다음주_이슈사항, '5', '예외', next)