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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| def faker_datas(number=7): """ 生成日志模板所需要的内容,一天一个默认7天,排除掉工作日(排除掉的也算一天) """ f = Faker(locale="zh_CN") datas = [] today = datetime.datetime.now().date() for n in range(0, number): date = today + datetime.timedelta(days=-n) if not is_workday(date): continue diary_log = {} diary_log["create_date"] = date str_time1 = date.strftime("%Y-%m-%d ") + "08:00:00" start_time = datetime.datetime.strptime(str_time1, "%Y-%m-%d %H:%M:%S") str_time2 = date.strftime("%Y-%m-%d ") + "11:00:00" end_time = datetime.datetime.strptime(str_time2, "%Y-%m-%d %H:%M:%S")
CreationTime = f.date_time_between(start_date=start_time, end_date=end_time) diary_log["CreationTime"] = CreationTime LastWriteTime = CreationTime + datetime.timedelta( hours=f.pyint(min_value=6, max_value=10), seconds=f.pyint(min_value=1, max_value=300), ) diary_log["LastWriteTime"] = LastWriteTime
LastAccessTime = LastWriteTime + datetime.timedelta( days=f.pyint(min_value=0, max_value=n), seconds=f.pyint(min_value=1, max_value=300), ) diary_log["LastAccessTime"] = LastAccessTime status_list = {"sucess": 80, "failed": 20} diary_log["status1"] = random_weight(status_list)
datas.append(diary_log) ......... ......... def main(number): ......... ......... jinja2_env = jinja2.Environment() tempate_data = open(template_file, encoding="utf-8").read() temp_out = jinja2_env.from_string(tempate_data).render({"datas": day_log})
file_name = day_log["create_date"].strftime("%Y-%m-%d") + ".md" output_file = OUTPUT / file_name with open(output_file, "w", encoding="utf-8") as f: f.writelines(temp_out)
args = ( "powershell.exe" + ' "ls ' + "'" + str(output_file) + "'" + " | foreach-object { $_.CreationTime = '" + day_log["CreationTime"].strftime("%m/%d/%Y %H:%M:%S") + "'; $_.LastWriteTime = '" + day_log["LastWriteTime"].strftime("%m/%d/%Y %H:%M:%S") + "'; $_.LastAccessTime = '" + day_log["LastAccessTime"].strftime("%m/%d/%Y %H:%M:%S") + "' }\"" ) subprocess.call(args, shell=True)
|