python篇---对时间序列进行排序,并按序列发送图片

python篇—对时间序列进行排序

import datetime
def get_timestamp(date):
    return datetime.datetime.strptime(date,"%Y-%m-%d %H:%M:%S").timestamp()
 
s1=[''2021-08-13 03:00:00', '2021-08-13 05:00:00', '2021-08-13 06:00:00'']
s=sorted(s1,key=lambda date: get_timestamp(date))

未排序前

import os
import datetime


img_path = "/app/yyq/dataset/fourth_project/wet_dataset/11.30"
img_file_ = os.listdir(img_path)
li_ti = []
for img in img_file_:
    img_ = os.path.join(img_path, img)
    print(img_)

python篇---对时间序列进行排序,并按序列发送图片_第1张图片

排序后

import os
import datetime


def get_timestamp(date):
    return datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S").timestamp()

img_path = "/app/yyq/dataset/fourth_project/wet_dataset/11.30"
img_file_ = os.listdir(img_path)
li_ti = []
for img in img_file_:
    img_ = os.path.join(img_path, img)
    # print(img_)

    find_time = img.split(".jpeg")[0][:10] + " " + img.split(".jpeg")[0][-8:].replace("-", ":")
    li_ti.append(find_time)

li_ti1 = sorted(li_ti, key=lambda date: get_timestamp(date))

for i in li_ti1:
    img_name = i[:10] + "-" + i[11:].replace(":", "-") + ".jpeg"
    print(os.path.join(img_path, img_name))

python篇---对时间序列进行排序,并按序列发送图片_第2张图片

你可能感兴趣的:(开发语言)