본문 바로가기

[Python] 파이썬 - 특정 시간에 자동 실행하는 프로그램

액트 2020. 10. 12.
반응형

매일 특정 시간에 실행되는 프로그램 있습니다.

매일 반복되는 작업을 위해 만들었습니다.

파이썬의 pyautogui 를 활용하여 마우스를 특정 좌표에 위치시키고 마우스를 클릭합니다. 

 

import pyautogui as m
import time, datetime
import schedule


try:

    def job():
        # 2초 후에
        time.sleep(2)
        #좌표 위치 입력 (x, y, 버튼, 횟수, 간격)
        #SQL Server(MSSQLSERVER) 서비스 클릭
        m.click(419, 188, button='left', clicks=1, interval=1)
        # 2초 후에
        time.sleep(2)
        #다시 시작 클릭
        m.click(197, 160, button='left', clicks=1, interval=1)
        # 2초 후에
        time.sleep(2)
        #예 클릭
        m.click(300, 318, button='left', clicks=1, interval=1)
        now = time.localtime()
        print("%04d/%02d/%02d %02d:%02d:%02d 클릭\n" % (now.tm_year,
                                                      now.tm_mon, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec))
    
    schedule.every().day.at("07:00").do(job)
    
    while True:
        schedule.run_pending()
        time.sleep(1)        

except KeyboardInterrupt:
    print('\b\bCtrl+C 를 눌러서 프로그램을 종료합니다.')

 print 출력 내용은 현재 시간을 출력해줍니다.

반응형

댓글