update esmart

This commit is contained in:
lychang
2025-09-23 02:39:47 +08:00
parent c60f65564e
commit 19e2c0281e
17 changed files with 114 additions and 29 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.idea
test.py
./groupchat/*.xlsx

2
.idea/misc.xml generated
View File

@@ -3,5 +3,5 @@
<component name="Black">
<option name="sdkName" value="Python 3.11 (image_recognition)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (scf)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (wxwork)" project-jdk-type="Python SDK" />
</project>

View File

@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.idea/dataSources" />
</content>
<orderEntry type="jdk" jdkName="Python 3.9 (scf)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.10 (wxwork)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">

119
esmart.py
View File

@@ -97,6 +97,33 @@ class SmartSheet:
return True
return False
def add_fields(self, fields: list[dict]):
url = "https://a.cmdp.cn/umss/v1/wxw/common/submit"
body = {
"url": "https://qyapi.weixin.qq.com/cgi-bin/wedoc/smartsheet/add_fields",
"method": "POST",
"body": {
"docid": self.doc_id,
"sheet_id": self.sheet_id,
"fields": fields
}
}
return self._post(url, body)
def delete_field(self, field_ids: list[str]):
url = "https://a.cmdp.cn/umss/v1/wxw/common/submit"
body = {
"url": "https://qyapi.weixin.qq.com/cgi-bin/wedoc/smartsheet/delete_fields",
"method": "POST",
"body": {
"docid": self.doc_id,
"sheet_id": self.sheet_id,
"field_ids": field_ids
}
}
return self._post(url, body)
def transform_data(self, data: dict):
result = {}
columns = self.columns
@@ -184,13 +211,56 @@ class SmartSheet:
return {"columns": self.columns, "data": data}
class SmartMetadata(SmartSheet):
def __init__(self, doc_id, sheet_id=None):
super().__init__(doc_id, sheet_id)
def create(self):
url = "https://a.cmdp.cn/umss/v1/wxw/addSheet"
body = {
"docid": self.doc_id,
"properties": {
"title": "Metadata"
}
}
resp = self._post(url, body)
if resp.get("properties"):
self.sheet_id = resp["properties"]["sheet_id"]
self.add_fields([
{
"field_type": "FIELD_TYPE_TEXT",
"field_title": "名称"
},
{
"property_single_select": {
"options": [{"style": 13, "text": "doc"},
{"style": 7, "text": "sheet"},
{"style": 11, "text": "metadata"}
],
"is_multiple": False,
"is_quick_add": True
},
"field_type": "FIELD_TYPE_SINGLE_SELECT",
"field_title": "类型"
}, {
"field_type": "FIELD_TYPE_TEXT",
"field_title": ""
}
])
self.delete_field([self.columns[i]["field_id"] for i in self.columns if i not in ["名称", "类型", ""]])
self.update(self.sheet_id, sheet_name="Metadata", sheet_type="metadata")
def update(self, sheet_id, sheet_name, sheet_type="sheet"):
self.add({"名称": sheet_name, "类型": sheet_type, "": sheet_id})
class SmartTableApi:
def __init__(self, doc_id):
def __init__(self, doc_id=None):
self.doc_id = doc_id
self.metadata_id = None
self._metadata = None
self.metadata_table = None
self._get_sheet_list()
if self.doc_id is not None:
self._get_sheet_list()
@staticmethod
def _post(url, body):
@@ -199,6 +269,18 @@ class SmartTableApi:
return resp.json()
return {}
def create(self, doc_name: str, admin_users: list[str]):
url = "https://a.cmdp.cn/umss/v1/wxw/addDocument"
body = {
"doc_type": 10,
"doc_name": doc_name,
"admin_users": admin_users
}
resp = self._post(url, body)
self.doc_id = resp.get("docid")
self._get_sheet_list()
self.metadata_table.update(self.doc_id, sheet_name=doc_name, sheet_type="doc")
def _get_sheet_list(self):
url = "https://a.cmdp.cn/umss/v1/wxw/common/submit"
body = {
@@ -212,22 +294,20 @@ class SmartTableApi:
resp = self._post(url, body)
sheet_list = resp.get("sheet_list", [])
result = {i["title"]: i["sheet_id"] for i in sheet_list}
self.metadata_id = result.get("Metadata")
if "Metadata" in result:
metadata_id = result.get("Metadata")
self.metadata_table = SmartMetadata(self.doc_id, metadata_id)
del result["Metadata"]
else:
self.metadata_table = SmartMetadata(self.doc_id)
self.metadata_table.create()
self._metadata = result
@property
def metadata(self):
return self._metadata
def _update_metadata(self, sheet_id, sheet_name):
if not self.metadata_table:
self.metadata_table = SmartSheet(self.doc_id, self.metadata_id)
self.metadata_table.add({"名称": sheet_name, "类型": "sheet", "": sheet_id})
pass
def add_sheet(self, sheet_name):
def _add_sheet(self, sheet_name):
url = "https://a.cmdp.cn/umss/v1/wxw/addSheet"
body = {
"docid": self.doc_id,
@@ -235,9 +315,12 @@ class SmartTableApi:
"title": sheet_name
}
}
resp = self._post(url, body)
return self._post(url, body)
def add_sheet(self, sheet_name):
resp = self._add_sheet(sheet_name)
if resp.get("properties"):
self._update_metadata(sheet_id=resp["properties"]["sheet_id"], sheet_name=sheet_name)
self.metadata_table.update(sheet_id=resp["properties"]["sheet_id"], sheet_name=sheet_name)
return resp
def get_sheet(self, sheet_id):
@@ -447,5 +530,11 @@ class ESmart:
if __name__ == '__main__':
esmart = ESmart()
esmart.prepared_message()
# esmart = ESmart()
# esmart.prepared_message()
sta = SmartTableApi("dcxzIyHG8nZDXswX00xaTDBGgW9NQ00Qk5WH6zLPTFONlE42y2CWZ8nCG8O-gvZSA5dRjTDASSThVAk2iWF16MAg")
sta.add_sheet("维护更新")
sta.add_sheet("VIP交付情况")
sta.add_sheet("备份存档")
# sta.create("推广-深交所用户智能跟踪",
# ["lychang", "rhu"])

View File

@@ -36,6 +36,8 @@ def parser_chat_text(content: str):
if __name__ == '__main__':
df = pd.read_excel("聊天记录.xlsx")
for group_name,group_messages in df.values:
if group_messages == " ":
continue
writer = pd.ExcelWriter(f"{group_name}-聊天记录分析.xlsx", engine="xlsxwriter")
chat_messages ,chat_analyzer = parser_chat_text(group_messages)
df1 = pd.DataFrame(chat_messages,columns=["user","date","time","content"])

Binary file not shown.

15
lib.py
View File

@@ -521,7 +521,7 @@ def parse_data(data: dict, mapping: dict) -> dict:
crop_id = "wx98dfa35ad7e4b271"
space_id = "s.wx98dfa35ad7e4b271.744621152iSk"
doc_id = 'dc1zao6J8YnS9p86FKKvKQadukmFXlXv3dU1qVQrgcjB81zdSVI7qoi9a7K_OpN4BTyXc8EbYVXxpnQNUUTMWwIw'
f_id = 'dc1zao6J8YnS9p86FKKvKQadukmFXlXv3dU1qVQrgcjB81zdSVI7qoi9a7K_OpN4BTyXc8EbYVXxpnQNUUTMWwIw'
wxc_app_secret = "gyN5moBa6Ev1Vd0ZLUVrsEtAO_goppWKUBdsnSng-Ks"
wapi_app_secret = "oM0hwIi8GRPw6HWk9o5__g3v5ziz5CGyBUo2FASSrVw"
wxc_auth = WXworkAuth(crop_id, wxc_app_secret)
@@ -718,7 +718,7 @@ class SalesTools:
return response.json().get("data", {})
@staticmethod
def get_report_rule(tags: [str]):
def get_report_rule(tags: list[str]):
"""
四.尽调报告的规则文件地址查询
@@ -906,7 +906,6 @@ class SalesTools:
"filter": "'fileInfo.extends.resource.delStatus' eq 1 and 'fileInfo.extends.resource.label' eq '小智智填-定期报告专版'",
"tags": ["tech_sbom", f"prod_year_{year}", "type_入口", "prod_小智转写"]
}
print(url, json.dumps(body, ensure_ascii=False))
response = requests.post(url, json=body)
if response.status_code == 200:
response_json = response.json()
@@ -1065,7 +1064,7 @@ class SalesTools:
resp = requests.get(basiceg_url + file_path)
if resp.status_code == 200:
data = resp.content
resp = requests.put(basiceg_url + static_path, data=data)
requests.put(basiceg_url + static_path, data=data)
return f'<img src="http://www.cmdp.cn/a/s/xpcjd/{security_code}_idsr.jpg" width="100%">'
else:
return ""
@@ -1096,12 +1095,6 @@ class CalendarEventDB(CalendarDB):
bp_id = bp_info.get("id")
bp_mail = bp_info.get("email")
# 获取二维码
# product_id = st.get_current_product_id()
# product_id ="1909049700811497474"
# st.get_smart_genie_product(eid, product_id)
# product_qrcode_path = st.get_product_qrcode(eid, product_id)
# qrcode = st.get_qrcode_base64(product_qrcode_path)
# 获取报告文件
now = time.localtime(time.time())
year = now.tm_year
@@ -1126,7 +1119,7 @@ class CalendarEventDB(CalendarDB):
# content = content.replace("{{qrcode}}", qrcode)
content = content.replace("{{picture}}", st.get_information_disclosure_picture("2024", security_code))
st.send_company_mail(bp_mail, f"客户拜访准备文件-{full_name}[{security_code}]", content)
ssp.add_row(doc_id=doc_id, sheet_id="tTMuVB", records=[
ssp.add_row(doc_id=f_id, sheet_id="tTMuVB", records=[
{
"values": {
"证券代码": [