normal_field.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # coding:utf-8
  2. import datetime
  3. def repair_time(body, field):
  4. if field not in body:
  5. return body
  6. this_time = body.get(field, "")
  7. try:
  8. dd = datetime.datetime.strptime(this_time, "%Y-%m-%d %H:%M:%S")
  9. print(type(dd))
  10. except Exception as e:
  11. print(e)
  12. del body[field]
  13. return body
  14. def repair_int(body, field):
  15. if field not in body:
  16. return body
  17. str_value = body.get(field, "")
  18. try:
  19. int_value = int(str_value)
  20. body[field] = int_value
  21. except Exception as e:
  22. print(e)
  23. del body[field]
  24. return body
  25. FieldCleanMap = {"time": repair_time, "int": repair_int}
  26. if __name__ == '__main__':
  27. times01 = "2022-04-02 10:47:42"
  28. body = {'unique_id': '123456', 'phone': '13373929153', 'isDelete': '', 'address': '',
  29. 'job': '', 'regtime': "2022-04-02 10:47:42", 'lastUpdateTime': "None",
  30. 'status999': 'status6'}
  31. body = repair_time(body, "regtime")
  32. body = repair_int(body, "lastUpdateTime")
  33. print(body)