Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- Python
- 생성AI
- Q
- review
- 태블로
- openAI
- 필사
- AWS
- 데일리
- Adobe
- 챗GPT
- 북리뷰
- 빅쿼리
- Ga
- 데이터시각화
- 파이썬
- SQL
- 데이터분석
- 서평
- tableau
- GPT
- ChatGPT
- 책리뷰
- AZURE
- datastudio
- 구글애널리틱스
- bigquery
- r
- daily
- diary
Archives
- Today
- Total
가볍게 배우고 깊게 즐기고 오래 남기기
Python || Slack API 내용을 일일 로그, 월별로그 남기는 코드 공유 (내 작업본의 일부 Sample) 본문
Programming & Tip/Python
Python || Slack API 내용을 일일 로그, 월별로그 남기는 코드 공유 (내 작업본의 일부 Sample)
Awesomist 2023. 8. 31. 23:59728x90
(S_msg : Slack MSG, E_msg : Excel MSG)
일별 로그
import openpyxl
import os
import shutil
from datetime import datetime
from openpyxl.utils import get_column_letter
def write_excel_log(S_msg):
List_msg = find_message_list(S_msg)
#S_msg 는 Response를 받은 값이라고 전제 함
user_name = S_msg.userName
if len(user_name) > 1:
user_name = user_name[0] + "**" + user_name[3:]
dateTime = datetime.utcfromtimestamp(float(S_msg.ts))
index = len(List_Excel_Logs) + 1
E_msg = Excel_Log()
E_msg.index = index
E_msg.channel_name = S_msg.channel_name
E_msg.ts = dateTime.strftime("%Y-%m-%d %H:%M:%S")
E_msg.user_name = user_name
E_msg.msg = S_msg.Slack_msg
List_Excel_Logs.append(E_msg)
TO_Date = datetime.now().strftime("%Y-%m-%d")
path = "{경로}"
FR_name = "My Log_template.xlsx" #참고할 로그 유형을 정의했다면.
TO_name = "Daily_log" + TO_Date + ".xlsx"
full_path = os.path.join(path, TO_name)
if not os.path.exists(full_path):
source_file = os.path.join(path, FR_name)
dest_file = os.path.join(path, TO_name)
shutil.copy(source_file, dest_file)
wb = openpyxl.load_workbook(full_path)
ws = wb.active
for i in range(index_log, len(List_Excel_Logs)):
# 데이터를 한 번에 추가합니다.
data_to_append = [
List_Excel_Logs[i].channel_name,
List_Excel_Logs[i].ts,
List_Excel_Logs[i].user_name,
List_Excel_Logs[i].msg
]
ws.append(data_to_append)
index_log += 1
wb.save(full_path)
월별 로그는 %Y-%m으로 기재하면 됨
반응형
'Programming & Tip > Python' 카테고리의 다른 글
Comments