#获取本地时间,For Example:2008/10/02 00:44:11
nowtime = time.localtime()
#print nowtime
data1,time1 = "",""
for i in range(3):
#如果获得时间是单数,则需要补位0
data1 += ("%02d" % nowtime[i])+'/'
#获得时间片的日期测试print data1[0:-1]
for i in range(3,6):
#如果获得日期是单数,则需要补位0
time1 += ("%02d" % nowtime[i])+':'
#获得时间片的时间测试print time1[0:-1]
#时间片的数据组合
time_area = data1[0:-1]+" "+time1[0:-1]
return time_area
def data_control(self):
#得到需要重写话单文件的路径及命名self.data_count
count = 0
data_time = self.data_data
data_number = self.data_number
dd = 1
for i in range(int(self.data_count)):
i += 1
last_time = data_time
last_data_number = data_number
temp = dd
last_count = i
if dd != 1:
last_count = last_count - end_count
#i += 1
#增加话单数据文件序号隔天重新计数
nowtime = time.localtime()
data_time = ""
for y in range(3):
#如果日期为单数需要补零
data_time += "%02d" % nowtime[y]
if data_time == last_time:
last_data_number = data_number
else:
#重置循环次数
end_count = i
last_count = 0
#制作标识为
dd = 2
#如果不相等,则重置时间序号
last_data_number = data_number = 0
#处理生成的文件路径数字超过4位
rebulid_number = "%04d" % int(str((int(last_data_number)+last_count))[-4:])
rebulid_path = self.initialization_path+self.data_prefixion+data_time+self.data_infix+rebulid_number+self.data_postfix
#从初始化路径中得到数据
tel_node = open(self.data_path,"r")
tel_node_new = open(rebulid_path,'w')
tel_list = tel_node.readlines()
for i in range(len(tel_list)):
#数据的第一行
new_list = tel_list[i].split(',')
for j in range(len(tel_list[i].split(','))):
#赛选存在日期的序列,i等于时间片序列的纵行位置
if '/' in tel_list[i].split(',')[j]:
#从原始列表中删除原始日期
new_list.remove(tel_list[i].split(',')[j])
#替换重新组合的日期时间
time_area = self.get_localtime()
new_list.insert(j,time_area)
#得到新的数据列表print new_list
#合成数据从列表中读出数据添加分割符
new_string = ""
for i in new_list:
new_string += str(i)+','
#print new_string[0:-1]
tel_node_new.writelines(new_string[0:-1])
count += 1
print "Execute!count=%s,current_time=%s,current_number=%s" % (count,data_time,rebulid_number)
log_path = open(".//config//run_log.txt",'w')
log_path.writelines("Execute!count=%s,current_time=%s,current_number=%s" % (count,data_time,rebulid_number))
time.sleep(10)
if __name__ == "__main__":
control = DataBase()
print "测试前请先核对您的文件路径是否正确!"
print control.data_path
choose = raw_input("确认请输入OK:")
print "程序开始执行"
control.data_control()
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/