From 233d41a833549a25344c2a3b38d303df53aee377 Mon Sep 17 00:00:00 2001 From: ztb-system Date: Tue, 3 Mar 2026 17:49:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=AE=80=E9=81=93=E4=BA=91=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E5=AD=97=E6=AE=B5=E8=BD=AC=E4=B8=BAISO=208601?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- processors/jiandaoyun.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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: """将价格字符串转为纯数字(元)"""