temp.py 631 B

123456789101112131415161718192021
  1. from databases import CRUD, SqlQuery, PhotoRecord
  2. from datetime import datetime
  3. session = SqlQuery()
  4. crud = CRUD(PhotoRecord)
  5. res = crud.read(session,conditions={"image_path":None})
  6. if res:
  7. time_str = "2025-03-26 19:29:39.954187"
  8. dt = datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S.%f")
  9. # 格式化为年月日时分
  10. formatted_time_str = dt.strftime("%Y-%m-%d %H:%M:%S")
  11. update = {
  12. "image_path": "sadasda",
  13. "image_index": 0,
  14. "photo_create_time": datetime.strptime(formatted_time_str, "%Y-%m-%d %H:%M:%S"),
  15. }
  16. crud.update(
  17. session,
  18. res.id,
  19. **update,
  20. )