diff --git a/processors/jiandaoyun.py b/processors/jiandaoyun.py index 6ac20b8..7c31fcf 100644 --- a/processors/jiandaoyun.py +++ b/processors/jiandaoyun.py @@ -22,6 +22,9 @@ class JiandaoyunUploader: # 需要转换为数字的字段 NUMERIC_FIELDS = {"最高限价", "最高投标限价", "预估金额", "招标估算金额"} + # 需要转换为日期的字段 + DATE_FIELDS = {"发布时间", "项目发布时间", "投标截止日", "招标时间"} + def __init__(self, api_key: str = None): self.api_key = api_key or JDY_CONFIG["api_key"] self.headers = { @@ -116,10 +119,30 @@ class JiandaoyunUploader: num = self._parse_price(value) if num is not None: jdy_data[jdy_field] = {"value": num} + elif local_field in self.DATE_FIELDS: + iso_date = self._to_iso8601(value) + if iso_date: + jdy_data[jdy_field] = {"value": iso_date} else: jdy_data[jdy_field] = {"value": value} return jdy_data + @staticmethod + def _to_iso8601(date_str: str) -> str: + """将日期字符串转为 ISO 8601 格式(北京时间 UTC+8)""" + if not date_str or date_str in ("文档未提及", "详见公告"): + return "" + s = str(date_str).strip() + from datetime import datetime as _dt + for fmt in ("%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d"): + try: + dt = _dt.strptime(s, fmt) + return dt.strftime("%Y-%m-%dT%H:%M:%S") + "+08:00" + except ValueError: + continue + # 无法解析,原样返回 + return s + @staticmethod def _parse_price(price_str) -> int | None: """将价格字符串转为纯数字(元)"""