1234567891011121314151617181920212223242526272829303132333435363738394041 |
- # coding:utf-8
- import datetime
- def repair_time(body, field):
- if field not in body:
- return body
- this_time = body.get(field, "")
- try:
- dd = datetime.datetime.strptime(this_time, "%Y-%m-%d %H:%M:%S")
- print(type(dd))
- except Exception as e:
- print(e)
- del body[field]
- return body
- def repair_int(body, field):
- if field not in body:
- return body
- str_value = body.get(field, "")
- try:
- int_value = int(str_value)
- body[field] = int_value
- except Exception as e:
- print(e)
- del body[field]
- return body
- FieldCleanMap = {"time": repair_time, "int": repair_int}
- if __name__ == '__main__':
- times01 = "2022-04-02 10:47:42"
- body = {'unique_id': '123456', 'phone': '13373929153', 'isDelete': '', 'address': '',
- 'job': '', 'regtime': "2022-04-02 10:47:42", 'lastUpdateTime': "None",
- 'status999': 'status6'}
- body = repair_time(body, "regtime")
- body = repair_int(body, "lastUpdateTime")
- print(body)
|