我写了一个程序(感谢Windows after starting
文件夹)在登录后启动,将当前时间写入日志,然后根据输入的名称(作为字符串)将信息放入日志中。
这是相当划分的时间我和我的兄弟可以在计算机上(这里不重要)我想让他无法控制(日志是当前的安全性)。
如果您选择(通过input()
),它会在将结束时间写入日志后立即关闭或退出计算机。
同时,它会将当前状态(有时间和有多少)写入cas.txt
(英文阅读time.txt
)。他和我很容易理解,有时我必须根据日志重写它,因为他"欺骗"。
日志文件名为zaznam.txt
。
我想以两种方式升级它:
我的操作系统是Windows 7
文件的样子(你实际上不需要阅读本文,只是表明我做了一些工作,没有什么可以帮助你回答):
cas.txt
(实际时间统计,易于访问)
Tonda 0:00:00
Janek 4 days, 12:01:20
意思是:
my name, my spend time
his name, his spend time
zaznam.txt
=日志中的一行(他可能不知道或不理解)注意:它被标签分开,所以在这里看到它并不容易:/
2015-10-22 11:58:38.024605 Tonda 0:00:00;Janek 3 days, 2:19:31 Janek 2015-10-22 12:37:59.020734 Tonda 0:00:00;Janek 3 days, 2:58:51
>>>>>>>time started<<<<<<< >>>>>what "cas.txt" looked like<<<< >inputed name< >>>>>>>>time ended<<<<<<<< >>>what "cas.txt" now looks like<<<
还有一个程序(我不认为对于没有捷克语的人来说很清楚):
import datetime
import time
a = datetime.datetime.today()
###
zaznam = open("zaznam.txt", 'a')
zaznam.write("\n")
zaznam.write(str(a))
oldcas = open("cas.txt", "r").read().replace("\n", ";")
print(oldcas)
zaznam.write("\t" + oldcas)
zaznam.close()
###
jmeno = None
while (jmeno != "Tonda") and (jmeno != "Janek"):
jmeno = input("Zadej jméno (Janek/Tonda):\n")
###
zaznam = open("zaznam.txt", 'a')
zaznam.write("\t" + jmeno)
zaznam.close()
###
turnoff = input("Zmáčkni enter pro ukončení a něco před tím napiš, pokud chceš vypnout PC")
b = datetime.datetime.today()
###
zaznam = open("zaznam.txt", 'a')
zaznam.write("\t" + str(b))
zaznam.close()
###
soubor = open("C:/Users/Tonda_2/Documents/Python/Cas/cas.txt", "r")
radek1, radek2 = soubor.read().split("\n")
soubor.close()
Tday, Jday = 0, 0
if " day, " in radek1:
Tday, Tcas = radek1.split(" day, ")
Tonda, Tday = Tday.split()
Tday = int(Tday)
elif " days, " in radek1:
Tday, Tcas = radek1.split(" days, ")
Tonda, Tday = Tday.split()
Tday = int(Tday)
else:
Tonda, Tcas = radek1.split(" ")
if " day, " in radek2:
Jday, Jcas = radek2.split(" day, ")
Janek, Jday = Jday.split()
Jday = int(Jday)
elif " days, " in radek2:
Jday, Jcas = radek2.split(" days, ")
Janek, Jday = Jday.split()
Jday = int(Jday)
else:
Janek, Jcas = radek2.split(" ")
Th, Tm, Ts = Tcas.split(":")
Jh, Jm, Js = Jcas.split(":")
Th, Tm, Ts, Jh, Jm, Js = int(Th) + 24*Tday, int(Tm), int(Ts), int(Jh) + 24*Jday, int(Jm), int(Js)
Tuhrano = datetime.timedelta(hours = Th, minutes = Tm, seconds = Ts)
Juhrano = datetime.timedelta(hours = Jh, minutes = Jm, seconds = Js)
uhrano = b - a
if jmeno == "Tonda":
Tuhrano += uhrano
if jmeno == "Janek":
Juhrano += uhrano
Tday, Jday = 0, 0
if " day, " in str(Tuhrano):
Tday, Tuhrano = str(Tuhrano).split(" day, ")
Tday = int(Tday)
if " days, " in str(Tuhrano):
Tday, Tuhrano = str(Tuhrano).split(" days, ")
Tday = int(Tday)
if " day, " in str(Juhrano):
Jday, Juhrano = str(Juhrano).split(" day, ")
Jday = int(Jday)
if " days, " in str(Juhrano):
Jday, Juhrano = str(Juhrano).split(" days, ")
Jday = int(Jday)
print()
print(Tuhrano)
print(Juhrano)
print()
Th, Tm, Ts = str(Tuhrano).split(":")
Jh, Jm, Js = str(Juhrano).split(":")
Tsec, Jsec = Ts.split("."), Js.split(".")
Ts, Js = Tsec[0], Jsec[0]
Th, Tm, Ts, Jh, Jm, Js = int(Th) + 24*Tday, int(Tm), int(Ts), int(Jh) + 24*Jday, int(Jm), int(Js)
if not "-" in str(datetime.timedelta(hours = Th - Jh, minutes = Tm - Jm, seconds = Ts - Js)):
Tondauhral = datetime.timedelta(hours = Th - Jh, minutes = Tm - Jm, seconds = Ts - Js)
Janekuhral = "0:00:00"
else:
Tondauhral = "0:00:00"
Janekuhral = datetime.timedelta(hours = Jh - Th, minutes = Jm - Tm, seconds = Js - Ts)
print("Tonda", Tondauhral)
print("Janek", Janekuhral)
soubor = open("C:/Users/Tonda_2/Documents/Python/Cas/cas.txt", "w")
soubor.write("Tonda" + " " + str(Tondauhral) + "\n" + "Janek" + " " + str(Janekuhral))
soubor.close()
###
zaznam = open("zaznam.txt", 'a')
oldcas = open("cas.txt", "r").read().replace("\n", ";")
zaznam.write("\t" + oldcas)
zaznam.close()
###
import os
if turnoff == "":
os.system("shutdown -l")
else:
os.system("shutdown -s -f")
#import subprocess
#subprocess.call(["shutdown /l", "-f", "-s", "-t", "5"]) #subprocess.call(["shutdown.exe", "-f", "-s", "-t", "5"])