You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
728 B
Python
33 lines
728 B
Python
from typing import List, Tuple
|
|
from datetime import datetime
|
|
|
|
|
|
def str2int(val, replace=0):
|
|
try:
|
|
val = int(val)
|
|
except ValueError:
|
|
val = replace
|
|
except TypeError:
|
|
val = replace
|
|
return val
|
|
|
|
|
|
def get_today_date(fmt: str = "%Y-%m-%d"):
|
|
return datetime.today().strftime(fmt)
|
|
|
|
|
|
def get_list_key(array: List[dict], target: str, condition: Tuple[str, str]):
|
|
"""
|
|
给定一个list [{key: val1, target: val2}, {key: val1, target: val2}]
|
|
根据condition(key=val)返回第一个target对应的值
|
|
:param target:
|
|
:param condition:
|
|
:param array:
|
|
:return:
|
|
"""
|
|
n, v = condition
|
|
for dic in array:
|
|
if dic.get(n) == v:
|
|
return dic.get(target)
|
|
|