def new_report(test_report):
lists = os.listdir(test_report) #列出目录的下所有文件和文件夹保存到lists
print(list)
lists.sort(key=lambda fn:os.path.getmtime(test_report + "\\" + fn))#按时间排序
file_new = os.path.join(test_report,lists[-1]) #获取最新的文件保存到file_new
print(file_new)
return file_new
if __name__=="__main__":
test_report="path"#目录地址
new_report(test_report)
df_data=dataPress(fileName)
# os.remove(u'./upload/{}'.format(fileName))
def get_filelist(dir, Filelist):
try:
lists = os.listdir(dir)
lists.sort(key=lambda fn:os.path.getmtime(dir + "\\" + fn))
if len(lists)>1:
lists=[i for i in lists if (R"xlsx" in i)]
for i in lists:
print(i)
if i !=lists[-1] or R"xlsx" not in i :
os.remove(u'./upload/{}'.format(i))
file_new = lists[-1]
print(file_new)
if R"xlsx" in file_new:
return file_new
# for s in os.listdir(dir):
# if R"xlsx" in s:
# print(s)
# Filelist.append(s)
# return Filelist[0]
except Exception,err:
print(err)
return Filelist
def dataPress(fileName):
print("done >>>>>>>>>>",fileName.decode("utf-8"))
try:
excel_reader=pd.ExcelFile(u'./upload/{}'.format(fileName))
except Exception,err:
if R"xlsx" in str(err):
df=pd.ExcelFile(u'./upload/{}'.format(fileName),engine='openpyxl')
sheet_names = excel_reader.sheet_names
lis=[]
if R"dataflow" in sheet_names:
df_data = excel_reader.parse(sheet_name="dataflow")
df_=df_data.iloc[1:5,1:5]
df_.iloc[:,2:4] = np.nan
for tup in df_.itertuples():
lis.append(tup[1:])
# print(tup[1:])
print(lis)
return lis
# result = _common.mysql_select(sql, withcolumns=False)