redmineに入れた実績が少なかった人をあぶり出すcsvファイルの作成スクリプト
2023/4/13
GPT-4で書き直しました
import csv
import os
import datetime
from collections import defaultdict
from redminelib import Redmine
# Redmineへのアクセス設定
redmine_url = 'https://your-redmine-url.com'
api_key = 'APIキー'
redmine = Redmine(redmine_url, key=api_key)
csvfile = os.path.basename(__file__) + ".csv"
# 前日の日付を取得
yesterday = (datetime.date.today() - datetime.timedelta(days=1)).strftime("%Y-%m-%d")
# 前日の時間の合計が8時間に満たない人を抽出
def find_users_with_less_than_8_hours():
time_entries = redmine.time_entry.filter(from_date=yesterday, to_date=yesterday)
user_time = defaultdict(float)
for entry in time_entries:
user_time[entry.user.id] += entry.hours
users_with_less_than_8_hours = []
all_users = redmine.user.all()
for user in all_users:
hours = user_time.get(user.id, 0)
if hours < 8:
users_with_less_than_8_hours.append((user.login, user.firstname ,user.lastname, hours))
return users_with_less_than_8_hours
# CSVファイルに出力
def export_to_csv(users_with_less_than_8_hours):
with open(f'less_than_8_hours_{yesterday}.csv', 'w', encoding='utf-8', newline='') as csvfile:
fieldnames = ['username', 'First Name' , 'Last Name' , 'total_hours']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for user in users_with_less_than_8_hours:
writer.writerow({'username': user[0], 'First Name': user[1], 'Last Name': user[2], 'total_hours': user[3]})
if __name__ == "__main__":
users_with_less_than_8_hours = find_users_with_less_than_8_hours()
export_to_csv(users_with_less_than_8_hours)