인턴십 미션은 Edu Ops에서 활용할 KDT 모니터링 자동화 프로그램을 구현하는 것이었어요.
KDT는 Zoom을 통해 진행되며, 교육 운영 매니저들이 하루 종일 교육 과정을 모니터링하느라 겪는 어려움을 해소하고, 동시에 교육이 원활히 진행되었음을 증빙할 수 있는 자료를 자동으로 기록하기 위한 목적입니다.
실행 프로그램
vs 웹 페이지
)
Python
vs JavaScript
)
Python
과정명_기수_날짜_YYMMDDHHMM.png
와 같은 형태로 파일명이 지정ImageGrab.grab()
: 화면 캡처, 자동화time
: 시간 처리, 대기os
: 파일 및 디렉토리 관리filedialog
: 폴더 선택 dialog를 띄우고, 선택된 경로 반환PyInstaller
: 독립 실행 파일 생성pydrive
: 구글 드라이브 업로드캡쳐 대기
상태로 시작.캡쳐 시작
버튼을 클릭하거나, 운영 시간이 되면 자동으로 캡처 시작.캡쳐 대기
상태로 변경.캡쳐 중지
버튼을 클릭하면 즉시 중지.테스트를 위해 10초마다 화면을 캡쳐하고 로컬에 저장한다.
import pyautogui
import time
def capture_screenshot():
# 현재 시간을 기준으로 파일 이름을 지정
filename = time.strftime("screenshot_%Y%m%d_%H%M%S.png")
# 전체 화면 캡쳐
screenshot = pyautogui.screenshot()
# 파일로 저장
screenshot.save(filename)
print(f"Screenshot saved as {filename}")
# 10초마다 캡쳐 (10초)
interval = 10
# 무한 루프로 5분마다 캡쳐 수행
while True:
capture_screenshot()
time.sleep(interval)
날짜별로 폴더를 생성하고, 해당 폴더 안에 캡쳐된 파일을 저장한다. 20250121
폴더가 새로 생겼다.
import pyautogui
import time
import os
def capture_screenshot():
# 현재 날짜를 기준으로 폴더 이름을 지정
date_str = time.strftime("%Y%m%d")
# 현재 시간을 기준으로 파일 이름을 지정
filename = time.strftime("screenshot_%Y%m%d_%H%M%S.png")
# 해당 날짜의 폴더가 존재하는지 확인하고, 없으면 생성
if not os.path.exists(date_str):
os.makedirs(date_str)
# 전체 화면 캡쳐
screenshot = pyautogui.screenshot()
# 파일 경로 지정하여 저장
filepath = os.path.join(date_str, filename)
screenshot.save(filepath)
print(f"Screenshot saved as {filepath}")
# 10초마다 캡쳐 (10초)
interval = 10
# 무한 루프로 캡쳐 수행
while True:
capture_screenshot()
time.sleep(interval)
실행 파일 실행 시, 창을 띄워 사용자가 파일 저장 위치를 지정할 수 있도록 tkinter
라이브러리를 사용한다.
import tkinter as tk
from tkinter import filedialog
def get_save_location():
root = tk.Tk()
root.withdraw() # 창을 숨깁니다
folder_selected = filedialog.askdirectory() # 저장할 폴더 선택
return folder_selected
교육 시간 내에만 화면 캡쳐가 이루어지도록 한다.
점심시간(12:00 ~ 13:00) 동안은 캡쳐가 일시 정지된다.
def in_operating_hours():
current_hour = time.localtime().tm_hour
# # 한국 시간 기준 (KST)
if (current_hour >= 9 and current_hour < 12) or (current_hour >= 13 and current_hour < 18):
return True
return False
PyInstaller
를 사용하여 실행 파일을 만들면, GUI에서 프로그램을 더 편리하게 실행할 수 있어, 터미널에 아래 명령어를 입력하여 단일 실행 파일을 생성한다.
pyinstaller --onefile --windowed --name "Auto Screenshot" auto_screenshot.py
하지만, 위의 명령어는 기존 .spec
파일을 덮어쓸 수 있어, 직접 파일을 지정하여 pyinstaller
명령어를 실행하도록 설정했다.
pyinstaller auto_screenshot.spec
[이슈]
.app
파일이 생성된다.[원인]
.exe
파일 형식이 필요하다.[해결 방법]
아래 블로그에서 이어서 확인할 수 있습니다.