Commit 796ac789 authored by machao's avatar machao

8.20的n8n配置文件

parent a9a22760
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyInterpreterInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="false" level="WARNING" enabled_by_default="false">
<option name="ignoredPackages">
<value>
<list size="25">
<item index="0" class="java.lang.String" itemvalue="bs4" />
<item index="1" class="java.lang.String" itemvalue="greenlet" />
<item index="2" class="java.lang.String" itemvalue="requests" />
<item index="3" class="java.lang.String" itemvalue="numpy" />
<item index="4" class="java.lang.String" itemvalue="redis" />
<item index="5" class="java.lang.String" itemvalue="pycrypto" />
<item index="6" class="java.lang.String" itemvalue="eventlet" />
<item index="7" class="java.lang.String" itemvalue="selenium" />
<item index="8" class="java.lang.String" itemvalue="ysb_common" />
<item index="9" class="java.lang.String" itemvalue="pymysql" />
<item index="10" class="java.lang.String" itemvalue="gevent" />
<item index="11" class="java.lang.String" itemvalue="urllib3" />
<item index="12" class="java.lang.String" itemvalue="beautifulsoup4" />
<item index="13" class="java.lang.String" itemvalue="dbutils" />
<item index="14" class="java.lang.String" itemvalue="Werkzeug" />
<item index="15" class="java.lang.String" itemvalue="opencv-python" />
<item index="16" class="java.lang.String" itemvalue="h5py" />
<item index="17" class="java.lang.String" itemvalue="gunicorn" />
<item index="18" class="java.lang.String" itemvalue="py_mini_racer" />
<item index="19" class="java.lang.String" itemvalue="Crypto" />
<item index="20" class="java.lang.String" itemvalue="htjs_apisdk" />
<item index="21" class="java.lang.String" itemvalue="aircv" />
<item index="22" class="java.lang.String" itemvalue="redis-py-cluster" />
<item index="23" class="java.lang.String" itemvalue="flask" />
<item index="24" class="java.lang.String" itemvalue="Pillow" />
</list>
</value>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (Twitter)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/n8n.iml" filepath="$PROJECT_DIR$/.idea/n8n.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
{
"createdAt": "2024-09-09T02:13:42.906Z",
"updatedAt": "2024-09-09T02:13:42.906Z",
"id": "YlcMg552EY5n0awF",
"name": "My workflow",
"active": false,
"nodes": [
{
"parameters": {},
"id": "d91dba08-3788-4984-9204-a370fd62053d",
"name": "When clicking ‘Test workflow’",
"type": "n8n-nodes-base.manualTrigger",
"position": [
420,
320
],
"typeVersion": 1
}
],
"connections": {},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "e1791629-ca48-4956-9a6f-1a3d8ac88f95",
"triggerCount": 0,
"shared": [
{
"createdAt": "2024-09-09T02:13:42.934Z",
"updatedAt": "2024-09-09T02:13:42.934Z",
"role": "workflow:owner",
"workflowId": "YlcMg552EY5n0awF",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-21T07:41:55.326Z",
"updatedAt": "2025-07-23T08:07:25.000Z",
"id": "RO90sPBakeItB8jK",
"name": "china_news_record",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source_china({{ (JSON.stringify($json.data))}});",
"options": {}
},
"id": "431fb3d8-b43d-4c30-bfea-6ad36ea0f798",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1180,
380
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\n// console.log(result_data);\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\noutput_all = [];\noutput_all_data = {};\noutput_news_url_data_str = \"\";\nnews_item_data = \"\";\n// news_item_data = news_item_data+\"(\";\n// news_item_data += \"'\"+info_data_list.topic+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.summary+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.source_content+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.content+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.source_url+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.author+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.author_head+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.likes+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.forward+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.hot+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.status+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.language+\"'\";\n// news_item_data += ',';\n// news_item_data += 'STR_TO_DATE(\\''+info_data_list.publish_time+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.news_uid+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+schedule_id+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.news_web+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.second_news_web+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.is_dual+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.is_translate+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.is_warn_dual+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.news_type+\"'\";\n// news_item_data += ')';\n\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+info_data_list.topic+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.content+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.author+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.source_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.publish_time+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.news_web+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.news_uid+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ')';\n\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '4';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '4';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\n\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all.push(output_all_data_temp);\nconsole.log(JSON.stringify(output_all_data));\nreturn output_all;"
},
"id": "5077c0e5-3910-4db2-a34a-70fb03956cf7",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
920,
380
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "06ce947a-5dec-451b-ba38-3891d15b5ccb",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
660,
660
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "71df056e-b02b-4028-b432-6c0fbaefd1dc",
"name": "return_save_flag",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1420,
380
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '0';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "12202645-1e6f-4ae7-a904-200eb590b412",
"name": "return_result",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
920,
680
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "chinanews/save",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "80e5221f-2f8e-4248-a7bf-fcb1a9cb5625",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
160,
660
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from report_news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).news_uid) }};\n",
"options": {}
},
"id": "de87cdf0-0730-4dc0-a973-c87e55d4cc9a",
"name": "is_exists_news1",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
420,
660
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
}
],
"connections": {
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
],
[
{
"node": "return_result",
"type": "main",
"index": 0
}
]
]
},
"insert_city_news": {
"main": [
[
{
"node": "return_save_flag",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news1",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news1": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "5dea225b-3c10-4c68-950e-ea4992f0abea",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-21T07:41:55.339Z",
"updatedAt": "2025-04-21T07:41:55.339Z",
"role": "workflow:owner",
"workflowId": "RO90sPBakeItB8jK",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-10T05:39:52.951Z",
"updatedAt": "2025-04-17T05:29:26.000Z",
"id": "PB5fUo8BrFYwlowK",
"name": "do_tw_label_interface",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "CALL do_label_news_source({{ JSON.stringify(JSON.stringify($json.is_warn))}},{{ JSON.stringify(JSON.stringify($json.news_id))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "2982694d-bc78-41b1-9fe5-22fcadade0a4",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1780,
400
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('label_data' in item_data){\n content_all['label'] = item_data['label_data'];\n }else if('artificial_label_data' in item_data){\n content_all['artificial_label'] = item_data['artificial_label_data'];\n }\n};\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nlabel_data_list = content_all.label;\nartificial_label_data_list = content_all.artificial_label;\nif(artificial_label_data_list.length>0){\n artificial_label_data_list[0]['city_code'] = info_data_list.city_code;\n}\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\noutput_all = [];\noutput_all_data_temp = {};\noutput_all_data_temp['is_warn'] = '0';\noutput_all_data_temp['news_id'] = info_data_list.id;\noutput_all_data_temp['label_data'] = label_data_list;\noutput_all_data_temp['artificial_label_data'] = artificial_label_data_list;\noutput_all.push(output_all_data_temp);\n// console.log(JSON.stringify(JSON.stringify(info_data_list.id)));\n// console.log(JSON.stringify(JSON.stringify(label_data_list)));\n// console.log(JSON.stringify(JSON.stringify(artificial_label_data_list)));\nreturn output_all;"
},
"id": "301f2cee-2c31-4f19-a5ab-5c5c8144fe91",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1480,
400
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\nfunction isEmpty(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value) {\n return true;\n }\n return false;\n};\nlabel_data_list = [];\nartificial_label_data_list = [];\nlabel_data_arr = $input.all();\nlabel_result_list = [];\nartificial_label_result_list = [];\nfor(var label_index=0;label_index<label_data_arr.length;label_index++){\n label_data_temp = label_data_arr[label_index];\n workflow_id = label_data_temp.json.data.workflow_id;\n label_data_output_list = label_data_temp.json.data.outputs;\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n for (let i = 0; i < label_result.length; i++) {\n label_result_list.push(label_result[i]);\n }\n }\n};\n// console.log(label_result_list);\nfor (let i = 0; i < label_result_list.length; i++) {\n label_code_score = {};\n label_code = label_result_list[i].code;\n // label_score = label_result_list[i].score;\n label_score = \"\";\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['score'] = label_score;\n label_data_list.push(label_code_score);\n }\n};\n\nlabel_data_list_2 = [];\nlabel_data_json = {};\nartificial_label_data_json = {};\nlabel_data_json[\"label_data\"] = label_data_list;\nartificial_label_data_json[\"artificial_label_data\"] = artificial_label_data_list;\n// console.log(label_data_json);\nlabel_data_list_2.push(label_data_json);\nlabel_data_list_2.push(artificial_label_data_json);\nreturn label_data_list_2;"
},
"id": "2c0617bc-cd95-4f1b-bc8a-3dca133f3cf4",
"name": "get_label_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1200,
400
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-2004545575-1912502751.ap-east-1.elb.amazonaws.com/api/v1/tag",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KNq0O8kENP4ITqSmqHQ0IzAt\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{JSON.stringify(JSON.parse($json.body.info).full_text).replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"{{ $json.body.source }}\"\n}",
"options": {
"response": {
"response": {}
}
}
},
"id": "7aa65121-d698-4fab-a461-9aa30b474b17",
"name": "news_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
920,
400
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/tag",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "79d406d0-27c6-4bd2-8db6-5ec2631d3572",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
640,
400
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_label_answer": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"news_label_dify": {
"main": [
[
{
"node": "get_label_answer",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "news_label_dify",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "95c7c5b5-baa9-4fc5-8b73-b874b8370a87",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-10T05:39:52.962Z",
"updatedAt": "2025-04-10T05:39:52.962Z",
"role": "workflow:owner",
"workflowId": "PB5fUo8BrFYwlowK",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-09T11:04:21.896Z",
"updatedAt": "2025-04-17T05:29:07.000Z",
"id": "53J8olMdTOSd0kSb",
"name": "do_tw_news_label",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "CALL do_label_news_source({{ JSON.stringify(JSON.stringify($json.is_warn))}},{{ JSON.stringify(JSON.stringify($json.news_id))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "0d003f02-9275-4899-a7a4-8629069cf367",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
2000,
200
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('label_data' in item_data){\n content_all['label'] = item_data['label_data'];\n }else if('artificial_label_data' in item_data){\n content_all['artificial_label'] = item_data['artificial_label_data'];\n }\n};\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nlabel_data_list = content_all.label;\nartificial_label_data_list = content_all.artificial_label;\nif(artificial_label_data_list.length>0){\n artificial_label_data_list[0]['city_code'] = info_data_list.city_code;\n}\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\noutput_all = [];\noutput_all_data_temp = {};\noutput_all_data_temp['is_warn'] = '0';\noutput_all_data_temp['news_id'] = info_data_list.id;\noutput_all_data_temp['label_data'] = label_data_list;\noutput_all_data_temp['artificial_label_data'] = artificial_label_data_list;\noutput_all.push(output_all_data_temp);\n// console.log(JSON.stringify(JSON.stringify(info_data_list.id)));\n// console.log(JSON.stringify(JSON.stringify(label_data_list)));\n// console.log(JSON.stringify(JSON.stringify(artificial_label_data_list)));\nreturn output_all;"
},
"id": "20325cad-de0c-4454-a146-f6399fe72a3f",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1680,
200
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\nfunction isEmpty(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value) {\n return true;\n }\n return false;\n};\nlabel_data_list = [];\nartificial_label_data_list = [];\nlabel_data_arr = $input.all();\nlabel_result_list = [];\nartificial_label_result_list = [];\nfor(var label_index=0;label_index<label_data_arr.length;label_index++){\n label_data_temp = label_data_arr[label_index];\n workflow_id = label_data_temp.json.data.workflow_id;\n label_data_output_list = label_data_temp.json.data.outputs;\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n for (let i = 0; i < label_result.length; i++) {\n label_result_list.push(label_result[i]);\n }\n }\n};\n// console.log(label_result_list);\nfor (let i = 0; i < label_result_list.length; i++) {\n label_code_score = {};\n label_code = label_result_list[i].code;\n // label_score = label_result_list[i].score;\n label_score = \"\";\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['score'] = label_score;\n label_data_list.push(label_code_score);\n }\n};\n\nlabel_data_list_2 = [];\nlabel_data_json = {};\nartificial_label_data_json = {};\nlabel_data_json[\"label_data\"] = label_data_list;\nartificial_label_data_json[\"artificial_label_data\"] = artificial_label_data_list;\n// console.log(label_data_json);\nlabel_data_list_2.push(label_data_json);\nlabel_data_list_2.push(artificial_label_data_json);\nreturn label_data_list_2;"
},
"id": "8431750a-fe99-48cb-bf58-6eeb9ec991bd",
"name": "get_label_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1360,
200
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-c06bddc665-962509615.ap-east-1.elb.amazonaws.com/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KNq0O8kENP4ITqSmqHQ0IzAt\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{JSON.stringify(JSON.parse($json.body.info).full_text).replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"{{ $json.body.source }}\"\n}",
"options": {}
},
"id": "bd458c53-9677-4a49-af75-b1a4633a4ac8",
"name": "news_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1060,
200
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/label",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "7f863b5a-062c-4e62-bf08-801e8e854262",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
760,
200
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"get_label_answer": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"news_label_dify": {
"main": [
[
{
"node": "get_label_answer",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "news_label_dify",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "7dc4a53e-98e7-4e82-b30e-afe42b2f9875",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-09T11:04:21.985Z",
"updatedAt": "2025-04-09T11:04:21.985Z",
"role": "workflow:owner",
"workflowId": "53J8olMdTOSd0kSb",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-09T09:13:38.677Z",
"updatedAt": "2025-04-09T09:13:55.000Z",
"id": "Q12P8Eg5KsOffglr",
"name": "do_tw_news_label_old",
"active": false,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "CALL do_label_news_source({{ JSON.stringify(JSON.stringify($json.news_id))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "659597f7-2353-4a78-bc63-9a0c5f713253",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1800,
660
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('label_data' in item_data){\n content_all['label'] = item_data['label_data'];\n }else if('artificial_label_data' in item_data){\n content_all['artificial_label'] = item_data['artificial_label_data'];\n }\n};\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nlabel_data_list = content_all.label;\nartificial_label_data_list = content_all.artificial_label;\nif(artificial_label_data_list.length>0){\n artificial_label_data_list[0]['city_code'] = info_data_list.city_code;\n}\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\noutput_all = [];\noutput_all_data_temp = {};\noutput_all_data_temp['news_id'] = info_data_list.id;\noutput_all_data_temp['label_data'] = label_data_list;\noutput_all_data_temp['artificial_label_data'] = artificial_label_data_list;\noutput_all.push(output_all_data_temp);\nconsole.log(JSON.stringify(JSON.stringify(info_data_list.id)));\nconsole.log(JSON.stringify(JSON.stringify(label_data_list)));\nconsole.log(JSON.stringify(JSON.stringify(artificial_label_data_list)));\nreturn output_all;"
},
"id": "039e80f4-c469-4901-aa5a-89fa539e7627",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1560,
660
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\nfunction isEmpty(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value) {\n return true;\n }\n return false;\n};\nlabel_data_list = [];\nartificial_label_data_list = [];\nlabel_data_arr = $input.all();\nlabel_result_list = [];\nartificial_label_result_list = [];\nfor(var label_index=0;label_index<label_data_arr.length;label_index++){\n label_data_temp = label_data_arr[label_index];\n workflow_id = label_data_temp.json.data.workflow_id;\n label_data_output_list = label_data_temp.json.data.outputs;\n if(workflow_id == '944449cb-15ad-4648-b3b0-3f103f574e09'){\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n for (let i = 0; i < label_result.length; i++) {\n label_result_list.push(label_result[i]);\n }\n }\n }else{\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n let label_index_temp = 0;\n for (let i = 0; i < label_result.length&&label_index_temp<1; i++) {\n artificial_label_result_list.push(label_result[i]);\n label_index_temp += 1;\n }\n } \n }\n};\n// console.log(label_result_list);\nfor (let i = 0; i < label_result_list.length; i++) {\n label_code_score = {};\n label_code = label_result_list[i].code;\n // label_score = label_result_list[i].score;\n label_score = \"\";\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['score'] = label_score;\n label_data_list.push(label_code_score);\n }\n};\nfor (let i = 0; i < artificial_label_result_list.length; i++) {\n label_code_score = {};\n label_code = artificial_label_result_list[i].code;\n label_name = artificial_label_result_list[i].name;\n // label_score = artificial_label_result_list[i].score;\n label_score = \"\";\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['name'] = label_name;\n label_code_score['score'] = label_score;\n artificial_label_data_list.push(label_code_score);\n }\n};\nlabel_data_list_2 = [];\nlabel_data_json = {};\nartificial_label_data_json = {};\nlabel_data_json[\"label_data\"] = label_data_list;\nartificial_label_data_json[\"artificial_label_data\"] = artificial_label_data_list;\n// console.log(label_data_json);\nlabel_data_list_2.push(label_data_json);\nlabel_data_list_2.push(artificial_label_data_json);\nreturn label_data_list_2;"
},
"id": "b708b6ae-e83e-429e-a2a8-2c636438ffa9",
"name": "get_label_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1300,
660
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KNq0O8kENP4ITqSmqHQ0IzAt\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{JSON.stringify(JSON.parse($json.body.info).full_text).replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "a344b263-78d1-4a95-bd7f-c170d995af36",
"name": "news_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
580,
920
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-HCbsiZmUCzP8Vdqb2meKXQSb\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{JSON.stringify(JSON.parse($json.body.info).full_text).replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "918e6b38-fe43-4763-bd8f-597587263a45",
"name": "artifi_nature_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
580,
440
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/label",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "292fe4cc-7b82-4aae-9c37-7e8e2d0b2616",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
120,
700
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
},
{
"parameters": {},
"id": "96a2e956-2a02-4c85-ab4d-a3be88790182",
"name": "merge_label",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
1060,
660
]
}
],
"connections": {
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"get_label_answer": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"news_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 1
}
]
]
},
"artifi_nature_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "artifi_nature_label_dify",
"type": "main",
"index": 0
},
{
"node": "news_label_dify",
"type": "main",
"index": 0
}
]
]
},
"merge_label": {
"main": [
[
{
"node": "get_label_answer",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "9d344072-3470-4428-a18d-80b8f2c15885",
"triggerCount": 0,
"shared": [
{
"createdAt": "2025-04-09T09:13:38.692Z",
"updatedAt": "2025-04-09T09:13:38.692Z",
"role": "workflow:owner",
"workflowId": "Q12P8Eg5KsOffglr",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-09T08:44:41.357Z",
"updatedAt": "2025-04-10T12:11:10.000Z",
"id": "DoI3eZkrbyruTDpX",
"name": "do_tw_warn_label",
"active": false,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "CALL do_label_news_source({{ JSON.stringify(JSON.stringify($json.is_warn))}},{{ JSON.stringify(JSON.stringify($json.news_id))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "914259be-88e4-4ba7-bc57-547b4a974f4d",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1680,
640
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('label_data' in item_data){\n content_all['label'] = item_data['label_data'];\n }else if('artificial_label_data' in item_data){\n content_all['artificial_label'] = item_data['artificial_label_data'];\n }\n};\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nlabel_data_list = content_all.label;\nartificial_label_data_list = content_all.artificial_label;\nif(artificial_label_data_list.length>0){\n artificial_label_data_list[0]['city_code'] = info_data_list.city_code;\n}\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\noutput_all = [];\noutput_all_data_temp = {};\noutput_all_data_temp['is_warn'] = '1';\noutput_all_data_temp['news_id'] = info_data_list.id;\noutput_all_data_temp['label_data'] = label_data_list;\noutput_all_data_temp['artificial_label_data'] = artificial_label_data_list;\noutput_all.push(output_all_data_temp);\nconsole.log(JSON.stringify(JSON.stringify(info_data_list.id)));\nconsole.log(JSON.stringify(JSON.stringify(label_data_list)));\nconsole.log(JSON.stringify(JSON.stringify(artificial_label_data_list)));\nreturn output_all;"
},
"id": "9abdf119-d44f-413c-9207-d2a678d17367",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1360,
640
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\nfunction isEmpty(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value) {\n return true;\n }\n return false;\n};\nlabel_data_list = [];\nartificial_label_data_list = [];\nlabel_data_arr = $input.all();\nlabel_result_list = [];\nartificial_label_result_list = [];\nfor(var label_index=0;label_index<label_data_arr.length;label_index++){\n label_data_temp = label_data_arr[label_index];\n workflow_id = label_data_temp.json.data.workflow_id;\n label_data_output_list = label_data_temp.json.data.outputs;\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n let label_index_temp = 0;\n for (let i = 0; i < label_result.length&&label_index_temp<1; i++) {\n artificial_label_result_list.push(label_result[i]);\n label_index_temp += 1;\n }\n } \n};\n// console.log(label_result_list);\nfor (let i = 0; i < label_result_list.length; i++) {\n label_code_score = {};\n label_code = label_result_list[i].code;\n // label_score = label_result_list[i].score;\n label_score = \"\";\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['score'] = label_score;\n label_data_list.push(label_code_score);\n }\n};\nfor (let i = 0; i < artificial_label_result_list.length; i++) {\n label_code_score = {};\n label_code = artificial_label_result_list[i].code;\n label_name = artificial_label_result_list[i].name;\n // label_score = artificial_label_result_list[i].score;\n label_score = \"\";\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['name'] = label_name;\n label_code_score['score'] = label_score;\n artificial_label_data_list.push(label_code_score);\n }\n};\nlabel_data_list_2 = [];\nlabel_data_json = {};\nartificial_label_data_json = {};\nlabel_data_json[\"label_data\"] = label_data_list;\nartificial_label_data_json[\"artificial_label_data\"] = artificial_label_data_list;\n// console.log(label_data_json);\nlabel_data_list_2.push(label_data_json);\nlabel_data_list_2.push(artificial_label_data_json);\nreturn label_data_list_2;"
},
"id": "23665425-2417-41f3-9b43-a77675d38e6e",
"name": "get_label_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1020,
640
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-HCbsiZmUCzP8Vdqb2meKXQSb\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{JSON.stringify(JSON.parse($json.body.info).full_text).replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "b64bb3f5-0804-43d4-9ab1-84806d0bdb2a",
"name": "artifi_nature_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
680,
640
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/warnlabel",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "799772f6-e9fc-4025-a512-5aed757325c5",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
340,
640
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"get_label_answer": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"artifi_nature_label_dify": {
"main": [
[
{
"node": "get_label_answer",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "artifi_nature_label_dify",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "8ce7b209-57ea-479a-8fbd-a51f8fd0d4df",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-09T08:44:41.373Z",
"updatedAt": "2025-04-09T08:44:41.373Z",
"role": "workflow:owner",
"workflowId": "DoI3eZkrbyruTDpX",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-03T04:56:41.542Z",
"updatedAt": "2025-04-17T05:23:20.000Z",
"id": "JrGxnBveuh26kpLw",
"name": "fy_test",
"active": false,
"nodes": [
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-c06bddc665-962509615.ap-east-1.elb.amazonaws.com/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-fxQiMsg03GrJCtwNfLRtnD4R\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"{{$json.source}}\"\n}",
"options": {}
},
"id": "874fc343-aab6-45e9-963d-6f09e323d218",
"name": "translate_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1300,
280
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\n// answer =$input.all()[0].json.data.outputs.result.answer;\nif('data' in $input.all()[0].json){\n answer =$input.all()[0].json.data.answer;\n}else{\n answer =$input.all()[0].json.answer;\n}\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nconsole.log(answer_data_json);\nreturn answer_data;"
},
"id": "d809825d-fcab-4728-ac24-114570e77466",
"name": "get_transter_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1520,
280
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo_data = JSON.parse($('Webhook').item.json.body.info);\ninfo_new = {};\nfor (let key in info_data) {\n if (info_data.hasOwnProperty(key)) {\n info_new[key] = info_data[key].replaceAll(/\"/g, '“')\n // console.log(info_data[key]); // 输出每个值\n }\n}\ninfo = JSON.stringify(info_new).replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ');\n// console.log(info);\noutput_info['text'] = info;\noutput_info['source'] = $('Webhook').item.json.body.source;\nreturn output_info;"
},
"id": "bb9f1fe7-817e-44b6-97ee-ce3550bb5cd0",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1080,
280
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL update_news_source_fy({{JSON.stringify($json.answer.toJsonString())}});",
"options": {}
},
"id": "69108b4b-1e4c-4288-9dd9-b80b3e960cf2",
"name": "update_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1740,
280
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/fy/test",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "a3e091cd-f33f-48f3-a69d-e5ac0d68f158",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
880,
280
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"translate_dify": {
"main": [
[
{
"node": "get_transter_answer",
"type": "main",
"index": 0
}
]
]
},
"get_transter_answer": {
"main": [
[
{
"node": "update_news",
"type": "main",
"index": 0
}
]
]
},
"get_info": {
"main": [
[
{
"node": "translate_dify",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "07796200-b05d-4f96-bbe2-b538e3d1eeda",
"triggerCount": 0,
"shared": [
{
"createdAt": "2025-04-03T04:56:41.551Z",
"updatedAt": "2025-04-03T04:56:41.551Z",
"role": "workflow:owner",
"workflowId": "JrGxnBveuh26kpLw",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-03T05:29:15.997Z",
"updatedAt": "2025-04-03T05:30:00.000Z",
"id": "AgrG6awFg4aff0Gk",
"name": "hostory_tw_search_no_fy",
"active": true,
"nodes": [
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = JSON.parse($('Webhook').item.json.body.info).full_text.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ').replaceAll(\"\\\"\", '” ');\n// console.log(info);\nuser_id = JSON.parse($('Webhook').item.json.body.info).id;\ntext_info['full_text'] = info;\noutput_info['text'] = JSON.stringify(text_info);\noutput_info['msg_info'] = info;\noutput_info['user_id'] = user_id;\nreturn output_info;"
},
"id": "b0d75bba-a4c2-44f1-986b-96b726d68cda",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1140,
420
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source_no_fy({{ (JSON.stringify($json.data))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "33011035-5b49-4222-a80c-7eb39c46a834",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1820,
420
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\n// console.log(result_data);\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nfull_text_origial = info_data_list.full_text.replace(/https:\\/\\/[^\\s]+/g, '');\n// full_text_origial = result_data[0].json.msg_info;\ninfo_data_list['full_text'] = full_text_origial\ninfo_data_list['full_text_ch'] = full_text_origial;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\nfull_text_new = info_data_list.full_text.replace(/'/g, \"\").replace(/\"/g, \"\");\nfull_text_ch_new = info_data_list.full_text_ch.replace(/'/g, \"\").replace(/\"/g, \"\");\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+full_text_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+full_text_ch_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.screen_name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.profile_image_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.favourite_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.retweet_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.view_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'zh_cn'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.created_at+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'twitter_search'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'1'\";\nnews_item_data += ')';\ncity_code = info_data_list.city_code;\nitem_data = \"(\";\nitem_data += \"'\"+city_code+\"'\";\nitem_data += ',';\nitem_data += '@last_insert_id';\nitem_data += '),';\noutput_news_data_str += item_data;\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all_data_temp['label_data'] = [];\noutput_all_data_temp['artificial_label_data'] = [];\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "917e8de1-0873-49b8-a0ef-dfa16f970401",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1480,
420
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n",
"options": {}
},
"id": "628a6cbe-be1e-4307-8fa4-cc8c728d03df",
"name": "update_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1140,
960
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "aaa69382-645a-4237-9562-2772974cf09b",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
740,
680
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "28825929-d1cf-47d1-936b-938a23b76801",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
500,
680
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\noutput_news_data_str = '';\noutput_all_data = {};\noutput_all = [];\noutput_city_code_list = [];\ncity_code = info_data_list.city_code;\noutput_city_code_list.push(city_code);\noutput_all_data['city_code'] = output_city_code_list;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all.push(output_all_data);\nconsole.log(output_all);\nreturn output_all;"
},
"id": "648edc41-f075-4afc-a0b4-fd96d5f0a7f9",
"name": "get_city_code_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1140,
700
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_city({{ JSON.stringify(JSON.stringify($json.city_code))}},{{ JSON.stringify(JSON.stringify($json.news_id)) }});",
"options": {}
},
"id": "8f51c5c2-c99a-432c-95c8-ae1f45394b4f",
"name": "insert_city_data",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1480,
700
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/history/nofy",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "576772ff-be37-43d8-95d0-284a782206e6",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
240,
680
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_info": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
],
[
{
"node": "update_city_news",
"type": "main",
"index": 0
},
{
"node": "get_city_code_info",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"get_city_code_info": {
"main": [
[
{
"node": "insert_city_data",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "a7a4325e-49f7-4a6c-9855-00e2c5f1c352",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-03T05:29:16.008Z",
"updatedAt": "2025-04-03T05:29:16.008Z",
"role": "workflow:owner",
"workflowId": "AgrG6awFg4aff0Gk",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-05-14T03:46:20.545Z",
"updatedAt": "2025-05-30T14:42:25.000Z",
"id": "7wjBhmUK3ogJiSob",
"name": "is_exists_crime",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from crime_mapping cm where cm.source_id ={{JSON.stringify(JSON.parse($json.body.info).id)}};\n",
"options": {}
},
"id": "758377a4-5621-4bf1-b5f6-cfdfc6bf7953",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
600,
360
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "crime/isexistsbyid",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "c04b872e-0f4a-42c9-b63d-3ab3e4cec6f3",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
340,
360
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "8946e5d6-a06c-4de4-8c5d-a1148e579cdf",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-05-14T03:46:20.560Z",
"updatedAt": "2025-05-14T03:46:20.560Z",
"role": "workflow:owner",
"workflowId": "7wjBhmUK3ogJiSob",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-03-27T07:12:40.892Z",
"updatedAt": "2025-04-23T08:10:35.000Z",
"id": "oReQ8D6vXdY0du2Q",
"name": "is_exists_news",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "9d403227-5f65-4d54-b4f6-53251509ba98",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-780,
920
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/isexistsbyid",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "c17e51fd-92e2-4105-ad63-da77bee99b86",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-1040,
920
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "f43961bb-63d3-44bc-a246-5e35902dcc8f",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-03-27T07:12:40.911Z",
"updatedAt": "2025-03-27T07:12:40.911Z",
"role": "workflow:owner",
"workflowId": "oReQ8D6vXdY0du2Q",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2024-09-12T09:04:59.778Z",
"updatedAt": "2024-09-12T10:08:13.000Z",
"id": "SSRzCtHJmpoNsal7",
"name": "myworkflow",
"active": false,
"nodes": [
{
"parameters": {
"table": {
"__rl": true,
"value": "city_safe_guide",
"mode": "list",
"cachedResultName": "city_safe_guide"
},
"options": {}
},
"id": "3897d8b1-7614-45ff-9aa5-a6cc289973ac",
"name": "MySQL",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1200,
160
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "MySQL account"
}
}
},
{
"parameters": {
"collection": "results_ls_fww",
"options": {},
"query": "{ \"schedule_id\": \"20\"}"
},
"id": "844aced7-ac0f-414e-a8d9-8f3973ebfb3a",
"name": "MongoDB",
"type": "n8n-nodes-base.mongoDb",
"typeVersion": 1.1,
"position": [
40,
80
],
"credentials": {
"mongoDb": {
"id": "D2GwCG2UAtnWPY8f",
"name": "MongoDB account"
}
}
},
{
"parameters": {
"path": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"options": {}
},
"id": "c5626b71-d366-4b9b-9239-aacdecefdb5b",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-120,
80
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07"
},
{
"parameters": {
"method": "POST",
"url": "http://47.99.137.247/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-ApuLSwN3ahfsL3CVAyKs3F0s\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"query\":\"{{ $json.info.replaceAll(/[ \\t\\n\\r]+/g, '')}} 请将上述内容按照以下json格式输出,并需要符合json schema规范 {{ JSON.stringify($json.attr).replaceAll(/\"/g, '\\'')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"mc\"\n}",
"options": {}
},
"id": "de50700e-6d6c-427f-9fa7-6e05e81780fd",
"name": "dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
520,
-100
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\ninfo = (JSON.parse($input.item.json.content)).实用信息;\noutput_info['info'] = info;\nreturn output_info;"
},
"id": "b1159cc1-1d2e-4ddb-b999-87c816c6405c",
"name": "content",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
280,
80
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\noutput_all = {};\noutput_data = {};\noutput_name_id = {};\nfor (const item of $input.all()) {\n output_data[item.json.name_cn] = \"xxx\";\n output_name_id[item.json.name_cn] = item.json.id;\n}\noutput_all['attr'] = output_data;\noutput_all['attr_id'] = output_name_id;\nreturn output_all;"
},
"id": "8833489f-a3d3-4fdf-a249-2912b818416a",
"name": "attribute",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
40,
-120
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select id,name_cn from code a where group_id = '10' and status = '0';",
"options": {}
},
"id": "194726be-688f-448c-b5f2-d28952258be8",
"name": "attribute_sql",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-120,
-120
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "MySQL account"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "select location from schedule a where a.id = {{$json.schedule_id}}\n",
"options": {}
},
"id": "74d2db72-a3c9-434f-94ba-d5098f83756b",
"name": "location_sql",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
60,
320
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "MySQL account"
}
}
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.item.json;\nlocation_data_list = JSON.parse(result_data.location);\nanswer_data = JSON.parse(result_data.answer);\nattr_id_data = JSON.parse(result_data.attr_id);\n_output_all = [];\nfor (let i = 0; i < location_data_list.length; i++) {\n cityCode = location_data_list[i].cityCode;\n for (let key in answer_data) {\n if (jsonData.hasOwnProperty(key)) { // 确保key是对象自身的属性\n console.log(key + \": \" + answer_data[key]);\n data_item = {};\n data_item['city_code'] = cityCode;\n data_item['recommend'] = JSON.stringify(answer_data[key]);\n data_item['classification_id'] = attr_id_data[key];\n _output_all.append(data_item);\n }\n }\n}\nreturn _output_all;"
},
"id": "c737a69f-0163-47bd-b863-70d7501187e7",
"name": "result",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
920,
160
]
},
{
"parameters": {
"method": "POST",
"url": "http://47.99.137.247/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-ApuLSwN3ahfsL3CVAyKs3F0s\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"query\":\"{{ $json.info.replaceAll(/[ \\t\\n\\r]+/g, '')}} 请将上述内容按照以下json格式输出,并需要符合json schema规范 {{ JSON.stringify($json.attr).replaceAll(/\"/g, '\\'')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"mc\"\n}",
"options": {}
},
"id": "fc981c2b-2d5e-4efa-9112-51b3dd45dae0",
"name": "dify1",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1500,
-740
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data_json = {\n \"meta\": {\n \"instanceId\": \"ece0f5d11a08367ce2b9a54872effc3097e741a5f11c32cdaf18af6d780d6a56\"\n },\n \"nodes\": [\n {\n \"parameters\": {\n \"mode\": \"runOnceForEachItem\",\n \"jsCode\": \"// Loop over input items and add a new field called 'myNewField' to the JSON of each one\\nlocation_data_list = $input.item.json;\\nfor (let i = 0; i < location_data_list.length; i++) {\\n cityCode = location_data_list[i].cityCode;\\n \\n}\"\n },\n \"id\": \"c737a69f-0163-47bd-b863-70d7501187e7\",\n \"name\": \"result\",\n \"type\": \"n8n-nodes-base.code\",\n \"typeVersion\": 2,\n \"position\": [\n 900,\n 260\n ]\n }\n ],\n \"connections\": {},\n \"pinData\": {}\n}\nresult_data = {};\nresult_data['answer'] = result_data_json;\nreturn result_data;"
},
"id": "aa3a70a6-8194-49fb-bece-3ca78ce03807",
"name": "result1",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
-260
]
},
{
"parameters": {
"mode": "combineBySql",
"numberInputs": 3
},
"id": "56ead3e5-fd33-4d83-b469-5d749f646602",
"name": "Merge2",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
1060,
-40
]
},
{
"parameters": {
"mode": "combineBySql"
},
"id": "b67162e6-cc85-4519-8d9c-ac8edefa9f33",
"name": "Merge",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
280,
-100
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nanswer = $input.item.json.answer;\nindexes = findAllIndexes(answer,\"```\");\nconsole.log(indexes[0]);\nanswer_data_json = JSON.parse(answer.slice(indexes[0]+7, indexes[1]));\nconsole.log(answer_data);\nanswer_data = {\"answer\":answer_data_json};\nreturn answer_data;"
},
"id": "debaa6fe-dfcc-479b-9297-0482ec381f2b",
"name": "answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
740,
-100
]
},
{
"parameters": {
"mode": "combineBySql",
"numberInputs": 3,
"query": "SELECT * FROM (SELECT * FROM input1 LEFT JOIN input2 ON input1.name = input2.id) as input1_1 LEFT JOIN input3 ON input1_1.name = input3.id"
},
"id": "b90aad45-fd1c-41ad-a960-fe35464b4928",
"name": "Merge1",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
600,
160
]
}
],
"connections": {
"MongoDB": {
"main": [
[
{
"node": "content",
"type": "main",
"index": 0
},
{
"node": "attribute_sql",
"type": "main",
"index": 0
},
{
"node": "location_sql",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "MongoDB",
"type": "main",
"index": 0
}
]
]
},
"content": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 1
}
]
]
},
"attribute": {
"main": [
[
{
"node": "Merge",
"type": "main",
"index": 0
}
]
]
},
"attribute_sql": {
"main": [
[
{
"node": "attribute",
"type": "main",
"index": 0
}
]
]
},
"dify": {
"main": [
[
{
"node": "answer",
"type": "main",
"index": 0
}
]
]
},
"location_sql": {
"main": [
[
{
"node": "Merge1",
"type": "main",
"index": 1
}
]
]
},
"Merge": {
"main": [
[
{
"node": "Merge1",
"type": "main",
"index": 0
},
{
"node": "dify",
"type": "main",
"index": 0
}
]
]
},
"answer": {
"main": [
[
{
"node": "Merge1",
"type": "main",
"index": 0
}
]
]
},
"Merge1": {
"main": [
[
{
"node": "result",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "da109e58-1c03-4b64-bd34-e3b84d841d02",
"triggerCount": 0,
"shared": [
{
"createdAt": "2024-09-12T09:04:59.787Z",
"updatedAt": "2024-09-12T09:04:59.787Z",
"role": "workflow:owner",
"workflowId": "SSRzCtHJmpoNsal7",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-02T09:53:30.470Z",
"updatedAt": "2025-04-17T05:27:34.000Z",
"id": "ZTzHvLotUJai7HJz",
"name": "news_fy_ch",
"active": true,
"nodes": [
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-c06bddc665-962509615.ap-east-1.elb.amazonaws.com/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-fxQiMsg03GrJCtwNfLRtnD4R\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"{{$json.source}}\"\n}",
"options": {}
},
"id": "37b55ad2-8565-4359-a32e-e9562ffb1311",
"name": "translate_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-280,
420
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\n// answer =$input.all()[0].json.data.outputs.result.answer;\nif(\"data\" in $input.all()[0].json){\n answer =$input.all()[0].json.data.answer;\n}else{\n answer =$input.all()[0].json.answer;\n}\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nconsole.log(answer_data_json);\nreturn answer_data;"
},
"id": "2d28fe0d-bfbe-4d7c-96a3-b4ea9ba59f05",
"name": "get_transter_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-60,
420
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo_data = JSON.parse($('Webhook').item.json.body.info);\ninfo_new = {};\nfor (let key in info_data) {\n if (info_data.hasOwnProperty(key)) {\n info_new[key] = info_data[key].replaceAll(/\"/g, '“')\n // console.log(info_data[key]); // 输出每个值\n }\n}\ninfo = JSON.stringify(info_new).replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ');\n// console.log(info);\noutput_info['text'] = info;\noutput_info['source'] = $('Webhook').item.json.body.source;\nreturn output_info;"
},
"id": "aab92007-74bf-44a0-a303-ae33f84e9bbf",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-500,
420
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL update_news_source_fy({{JSON.stringify($json.answer.toJsonString())}});",
"options": {}
},
"id": "6ab9f613-438d-4f0d-bcca-a60d40da793a",
"name": "update_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
160,
420
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/fy",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "89e13d80-12a2-4fda-8fc4-66c32cb762a3",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-700,
420
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"translate_dify": {
"main": [
[
{
"node": "get_transter_answer",
"type": "main",
"index": 0
}
]
]
},
"get_info": {
"main": [
[
{
"node": "translate_dify",
"type": "main",
"index": 0
}
]
]
},
"get_transter_answer": {
"main": [
[
{
"node": "update_news",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "0a616563-b3d6-4dff-adb2-2642663bdc63",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-02T09:53:30.479Z",
"updatedAt": "2025-04-02T09:53:30.479Z",
"role": "workflow:owner",
"workflowId": "ZTzHvLotUJai7HJz",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-10T11:35:42.002Z",
"updatedAt": "2025-04-17T05:28:15.000Z",
"id": "W1kv1npao4fkCv5z",
"name": "news_fy_ch_interface",
"active": true,
"nodes": [
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-2004545575-1912502751.ap-east-1.elb.amazonaws.com/api/v1/translate",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-fxQiMsg03GrJCtwNfLRtnD4R\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"{{$json.source}}\"\n}",
"options": {}
},
"id": "7b59e4f1-43fb-4b59-9351-f6daa1f5c835",
"name": "translate_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
940,
440
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\n// answer =$input.all()[0].json.data.outputs.result.answer;\n// answer =$input.all()[0].json.answer;\nanswer =$input.all()[0].json.data.answer;\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nconsole.log(answer_data_json);\nreturn answer_data;"
},
"id": "ced3e66e-220d-415c-ac38-aeff8ba89131",
"name": "get_transter_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1160,
440
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = $('Webhook').item.json.body.info.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ');\n// console.log(info);\noutput_info['text'] = info;\noutput_info['source'] = $('Webhook').item.json.body.source;\nreturn output_info;"
},
"id": "5a2854b0-635c-40c5-b33e-c6ad1f0ad272",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
720,
440
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL update_news_source_fy({{JSON.stringify($json.answer.toJsonString())}});",
"options": {}
},
"id": "4ef4cd8b-1203-4122-9111-cd306732a95a",
"name": "update_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1380,
440
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/fy/interface",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "5efd4ffc-2d8b-457b-a8c2-fdb60e6ceccd",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
520,
440
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"translate_dify": {
"main": [
[
{
"node": "get_transter_answer",
"type": "main",
"index": 0
}
]
]
},
"get_transter_answer": {
"main": [
[
{
"node": "update_news",
"type": "main",
"index": 0
}
]
]
},
"get_info": {
"main": [
[
{
"node": "translate_dify",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "d07faa68-c423-4faf-bc85-85b37180d0cd",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-10T11:35:42.015Z",
"updatedAt": "2025-04-10T11:35:42.015Z",
"role": "workflow:owner",
"workflowId": "W1kv1npao4fkCv5z",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-15T06:39:34.723Z",
"updatedAt": "2025-04-23T09:22:33.000Z",
"id": "zGsyn7KKfOFitXKB",
"name": "news_fy_label",
"active": true,
"nodes": [
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = $('Webhook').item.json.body.info.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ');\n// console.log(info);\noutput_info['text'] = info;\noutput_info['source'] = $('Webhook').item.json.body.source;\nreturn output_info;"
},
"id": "441640cc-5ff8-4feb-a009-bfe9dd5bc20e",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-1460,
580
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-c06bddc665-962509615.ap-east-1.elb.amazonaws.com/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-dZITr9ks9nCa1jTnGFwefjPN\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"{{$json.source}}\"\n}",
"options": {}
},
"id": "279f0281-a451-4d4d-be9f-c94cf33a9ed9",
"name": "translate_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-1260,
580
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL do_fy_label_news_source({{ JSON.stringify((JSON.stringify($json.answer)))}});",
"options": {}
},
"id": "89631bf4-5598-41a9-aaf9-0692a0dcd11e",
"name": "update_news_source",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-540,
400
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\nanswer = JSON.stringify($input.all()[0].json.data.outputs.answer);\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"finish_reason\"] = answer_data_json.finish_reason;\n// answer_data[\"finish_reason\"] = 'content_filter';\nanswer_data[\"answer\"] = answer_data_json.result;\n// console.log(answer_data_json.result);\nreturn answer_data;"
},
"id": "f35f6f37-b3df-49a5-8c8f-10ec1df9d4b1",
"name": "get_finish_reason",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-1060,
580
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.finish_reason }}",
"rightValue": "=stop",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "a0481ff8-c36e-46fd-a972-dc6dbcb0b84a",
"name": "is_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-860,
580
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.finish_reason }}",
"rightValue": "=content_filter",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "722ad79b-0fd1-4685-a222-3f0bbec3662d",
"name": "is_send_msg",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-540,
740
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\ninfo_data = $input.all()[0].json.answer;\nids_str = \"\";\nfor(var i=0;i<info_data.length;i++){\n ids_str = ids_str+info_data[i].id+\",\";\n}\nids_str = ids_str.slice(0, -1);\nfunction getFormattedDate() {\n const now = new Date();\n\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, '0'); // 补零\n const day = String(now.getDate()).padStart(2, '0');\n\n const hours = String(now.getHours()).padStart(2, '0');\n const minutes = String(now.getMinutes()).padStart(2, '0');\n const seconds = String(now.getSeconds()).padStart(2, '0');\n\n return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;\n}\ninfo_content = \"## 翻译异常\\n >主键ID:<font color=\\\"comment\\\">\"+ids_str+\"</font>\\n>原因:<font color=\\\"comment\\\">content_filter</font>\\n>失败时间:<font color=\\\"warning\\\"> \"+getFormattedDate()+\"</font>\\n>\";\noutput_all_data = {};\noutput_all = [];\noutput_all_data['content'] = info_content;\noutput_all.push(output_all_data);\n// console.log(output_all);\nreturn output_all;"
},
"id": "bdd4d504-c3d7-4073-9cc6-476b56e1a05b",
"name": "get_msg_content",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-320,
660
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-f24629df48-1909191723.ap-east-1.elb.amazonaws.com/api/v1/msg",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"content\": {{ JSON.stringify($json.content) }}\n }\n }",
"options": {}
},
"id": "8d7f62ea-3505-4ecc-9829-f5e7b7465eec",
"name": "send_msg",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-120,
660
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/fy_label",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "bc5e0e93-e780-4b35-ad8e-1ac9797ffe2f",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-1640,
580
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_info": {
"main": [
[
{
"node": "translate_label_dify",
"type": "main",
"index": 0
}
]
]
},
"translate_label_dify": {
"main": [
[
{
"node": "get_finish_reason",
"type": "main",
"index": 0
}
]
]
},
"get_finish_reason": {
"main": [
[
{
"node": "is_update",
"type": "main",
"index": 0
}
]
]
},
"is_update": {
"main": [
[
{
"node": "update_news_source",
"type": "main",
"index": 0
}
],
[
{
"node": "is_send_msg",
"type": "main",
"index": 0
}
]
]
},
"get_msg_content": {
"main": [
[
{
"node": "send_msg",
"type": "main",
"index": 0
}
]
]
},
"is_send_msg": {
"main": [
[
{
"node": "get_msg_content",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "5073d38a-ccff-4a24-9e89-251a92d1a07b",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-15T06:39:34.738Z",
"updatedAt": "2025-04-15T06:39:34.738Z",
"role": "workflow:owner",
"workflowId": "zGsyn7KKfOFitXKB",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": " <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "",
"lastName": "",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-05-12T07:57:59.471Z",
"updatedAt": "2025-06-22T04:28:30.000Z",
"id": "tOFAJrJIdWyFzICZ",
"name": "report_news_is_exists",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from {{JSON.parse($json.body.info).table_name}} where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "d594a15f-4f16-491d-a599-cdd4f43daf9d",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1040,
360
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "report/isexistsbyid",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "03ef4ef5-8a95-44df-b31e-4c9791b60b74",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
780,
360
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "73bb79b2-2034-452b-b983-97de2d0ca644",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-05-12T07:57:59.485Z",
"updatedAt": "2025-05-12T07:57:59.485Z",
"role": "workflow:owner",
"workflowId": "tOFAJrJIdWyFzICZ",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-07-21T02:34:58.955Z",
"updatedAt": "2025-07-23T07:13:45.000Z",
"id": "JBACXzRYBxqJc14O",
"name": "save_earthquake_data",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO earthquake_mapping (zone,title,mag,place,event_time,url,detail,mmi,alert,status,tsunami,sig,code,nst,dmin,rms,gap,magType) VALUES {{ $json.earthquake_data }};\n\nCOMMIT;",
"options": {
"detailedOutput": false
}
},
"id": "72be391f-a013-4a59-bb3a-e5da88be2f88",
"name": "insert_safe",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
720,
300
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "37fd1a36-8c69-4438-8fdc-6181956dfae3",
"leftValue": "={{ $json.source_num.toString()}}",
"rightValue": "0",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "42e3ce8d-43db-4203-ad26-127428cbd5b4",
"name": "If_1",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
140,
420
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "7441f842-2726-4f3c-80fb-fcd045e8b49a",
"name": "return_save_flag",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
940,
300
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '0';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "646995ad-c277-449b-879b-5547507a6a63",
"name": "return_save_flag2",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
460,
500
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "earthquake/save",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "081b0ac4-9c96-466e-9576-8728e09655c3",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-260,
420
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as source_num from earthquake_mapping cm where cm.code ={{JSON.stringify(JSON.parse($json.body.info).code)}};\n\n",
"options": {}
},
"id": "f233f48b-69a1-4517-a5c4-2ee6c3068ce7",
"name": "is_exist",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-60,
420
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\ninfo_data_list = JSON.parse($('Webhook').item.json.body.info);\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+info_data_list.zone+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.title+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.mag+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.place+'\"';\nnews_item_data += ',';\nif(!isEmptyString(info_data_list.event_time)){\n news_item_data += 'STR_TO_DATE(\"'+info_data_list.event_time+'\",\"%Y-%m-%d %H:%i:%s\")';\n news_item_data += ',';\n}else{\n news_item_data += 'STR_TO_DATE(NOW(),\"%Y-%m-%d %H:%i:%s\")';\n news_item_data += ',';\n};\nnews_item_data += '\"'+info_data_list.url+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.detail+'\"';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.mmi+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.alert+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.status+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.tsunami+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.sig+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.code+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.nst+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.dmin+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.rms+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.gap+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.magType+'\"';\nnews_item_data += ')';\noutput_all_data['earthquake_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "f539dc9b-18ca-4cec-9ae9-c38f5f604a90",
"name": "get_earthquake_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
460,
300
]
}
],
"connections": {
"insert_safe": {
"main": [
[
{
"node": "return_save_flag",
"type": "main",
"index": 0
}
]
]
},
"If_1": {
"main": [
[
{
"node": "get_earthquake_sql",
"type": "main",
"index": 0
}
],
[
{
"node": "return_save_flag2",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exist",
"type": "main",
"index": 0
}
]
]
},
"is_exist": {
"main": [
[
{
"node": "If_1",
"type": "main",
"index": 0
}
]
]
},
"get_earthquake_sql": {
"main": [
[
{
"node": "insert_safe",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "81dec0dc-74fc-4456-af98-deff009c4333",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-07-21T02:34:58.967Z",
"updatedAt": "2025-07-21T02:34:58.967Z",
"role": "workflow:owner",
"workflowId": "JBACXzRYBxqJc14O",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T10:33:28.698Z",
"updatedAt": "2025-04-15T02:40:03.000Z",
"id": "OOzu6qnvABmNOA2k",
"name": "send_twitter_wrong_msg",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(1), 0) as count from (\nselect a.rw_id,screen_name,occur_date from craw_warn_log_info a where a.rw_id = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.schedule_id)) }} and a.screen_name = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.info).user_screen_name) }} and a.content like '%429%' and a.status =0 group by screen_name,occur_date) as craw_warn_info;\n",
"options": {}
},
"id": "39c485eb-21e6-4686-a529-f76bac5c33ed",
"name": "is_exists_warn_by_retry",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
80,
780
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(1), 0) as count from (\nselect a.rw_id,screen_name,occur_date from craw_warn_log_info a where a.rw_id = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.schedule_id)) }} and a.screen_name = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.info).user_screen_name) }} and (a.content not like '%429%' and a.content not like '%403%' and LENGTH(TRIM(a.content))>0) and a.status =0 group by screen_name,occur_date) as craw_warn_info;\n",
"options": {}
},
"id": "e3eea07a-dc56-41c7-8ac7-73ad763235ef",
"name": "is_exists_warn_other",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
80,
1040
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{$json.count}}",
"rightValue": 1,
"operator": {
"type": "number",
"operation": "gte"
}
},
{
"id": "07df41b0-7a65-44b1-891c-c97406fa6764",
"leftValue": "={{JSON.parse($('Webhook').all()[0].json.body.info).error_info }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "26823d37-d175-401b-9f17-28f500dd8a8e",
"name": "is_send_msg_judge",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
280,
1040
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{$json.count}}",
"rightValue": 3,
"operator": {
"type": "number",
"operation": "gte"
}
},
{
"id": "e16adaf5-6fd5-4a12-b6b4-f3c55e643fae",
"leftValue": "={{JSON.parse($('Webhook').all()[0].json.body.info).error_info }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "6378e170-35cd-415b-91a5-0d06309104b3",
"name": "is_send_msg",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
280,
780
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select a.`name` from schedule a where a.id = {{ JSON.parse($('Webhook').all()[0].json.body.schedule_id) }};\n",
"options": {}
},
"id": "691dd49f-a745-409e-a94e-91924ab2a074",
"name": "get_rw_name",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
480,
900
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\ninfo_data = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = JSON.parse($('Webhook').all()[0].json.body.schedule_id);\nrw_name = $('get_rw_name').all()[0].json.name;\ninfo_content = \"## twitter采集异常\\n >ID:<font color=\\\"comment\\\">\"+schedule_id+\"</font>\\n>任务名称:<font color=\\\"comment\\\">\"+rw_name+\"</font>\\n>博主名称:<font color=\\\"comment\\\">\"+info_data.user_screen_name+\"</font>\\n>原因:<font color=\\\"comment\\\"> \"+info_data.error_info+\"</font>\\n>失败时间:<font color=\\\"warning\\\"> \"+info_data.occur_date+\"</font>\\n>详情页:<font color=\\\"comment\\\"> [http://16.162.124.172:8080/#/tasks](http://16.162.124.172:8080/#/tasks)</font>\";\noutput_all_data = {};\noutput_all = [];\noutput_all_data['content'] = info_content;\noutput_all.push(output_all_data);\n// console.log(output_all);\nreturn output_all;"
},
"id": "57ea2125-66ec-40f4-9c71-2ff8ea9d45db",
"name": "get_msg_content",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
900
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-f24629df48-1909191723.ap-east-1.elb.amazonaws.com/api/v1/msg1",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"content\": {{ JSON.stringify($json.content) }}\n }\n }",
"options": {}
},
"id": "2bd4eb67-e56a-4150-bb95-f5263b73c398",
"name": "send_msg",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
800,
900
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "update craw_warn_log_info set status = 1 where rw_id = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.schedule_id)) }} and screen_name = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.info).user_screen_name) }}\n",
"options": {}
},
"id": "dcdfc88f-5a69-4cc3-83fd-4ea375e59aaa",
"name": "update_warn_info",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
960,
900
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_fail_log({{ JSON.stringify($json.body.info)}},{{JSON.stringify(JSON.stringify($json.body.schedule_id)) }});\n",
"options": {}
},
"id": "ca9e1a9f-fbda-49e9-bdf5-a171ee58ace2",
"name": "insert_fail_log",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-140,
920
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/fail",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "866b4051-927c-4258-8fd1-2371b0c1e1c1",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-300,
920
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"is_exists_warn_by_retry": {
"main": [
[
{
"node": "is_send_msg",
"type": "main",
"index": 0
}
]
]
},
"is_exists_warn_other": {
"main": [
[
{
"node": "is_send_msg_judge",
"type": "main",
"index": 0
}
]
]
},
"is_send_msg_judge": {
"main": [
[
{
"node": "get_rw_name",
"type": "main",
"index": 0
}
]
]
},
"is_send_msg": {
"main": [
[
{
"node": "get_rw_name",
"type": "main",
"index": 0
}
]
]
},
"get_rw_name": {
"main": [
[
{
"node": "get_msg_content",
"type": "main",
"index": 0
}
]
]
},
"get_msg_content": {
"main": [
[
{
"node": "send_msg",
"type": "main",
"index": 0
}
]
]
},
"send_msg": {
"main": [
[
{
"node": "update_warn_info",
"type": "main",
"index": 0
}
]
]
},
"insert_fail_log": {
"main": [
[
{
"node": "is_exists_warn_by_retry",
"type": "main",
"index": 0
},
{
"node": "is_exists_warn_other",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "insert_fail_log",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "fab25e65-1d54-4ac3-bbe9-4b5679821fdf",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T10:33:28.725Z",
"updatedAt": "2025-02-13T10:33:28.725Z",
"role": "workflow:owner",
"workflowId": "OOzu6qnvABmNOA2k",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": " <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "",
"lastName": "",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-07-23T08:05:38.371Z",
"updatedAt": "2025-07-29T09:45:50.000Z",
"id": "YXxHyq5d7cxKvvGu",
"name": "test_china_news_record",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source_china({{ (JSON.stringify($json.data))}});",
"options": {}
},
"id": "1cb8e075-9a3a-49c7-9c4a-d14e95641f9d",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1180,
380
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\n// console.log(result_data);\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\noutput_all = [];\noutput_all_data = {};\noutput_news_url_data_str = \"\";\nnews_item_data = \"\";\n// news_item_data = news_item_data+\"(\";\n// news_item_data += \"'\"+info_data_list.topic+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.summary+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.source_content+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.content+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.source_url+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.author+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.author_head+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.likes+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.forward+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.hot+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.status+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.language+\"'\";\n// news_item_data += ',';\n// news_item_data += 'STR_TO_DATE(\\''+info_data_list.publish_time+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.news_uid+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+schedule_id+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.news_web+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.second_news_web+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.is_dual+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.is_translate+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.is_warn_dual+\"'\";\n// news_item_data += ',';\n// news_item_data += \"'\"+info_data_list.news_type+\"'\";\n// news_item_data += ')';\n\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+info_data_list.topic+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.content+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.author+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.source_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'1'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.publish_time+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.news_web+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.news_uid+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.country+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.area+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.city+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.rank+\"'\";\nnews_item_data += ')';\n\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '4';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '4';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\n\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all.push(output_all_data_temp);\nconsole.log(JSON.stringify(output_all_data));\nreturn output_all;"
},
"id": "d5344e45-ec5b-4070-bbf1-82cfd6c862db",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
920,
380
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "a4d5bb75-5839-4750-9aca-631b5787d263",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
660,
660
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "b5beed33-6b5c-4cca-87d7-1256b63bc9b7",
"name": "return_save_flag",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1420,
380
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '0';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "2d53dfa9-2be2-4681-9371-ecf94ade9251",
"name": "return_result",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
920,
680
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "chinanews/save/test",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "cf3f9f20-831e-4fea-9ee6-12d011d5e507",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
160,
660
],
"webhookId": "0db425bb-49ac-483b-acd6-49efda1cb2c1",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from report_news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).news_uid) }};\n",
"options": {}
},
"id": "6d8af4a6-9b03-45e0-9b53-8bd97b911eb4",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
420,
660
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
}
],
"connections": {
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
],
[
{
"node": "return_result",
"type": "main",
"index": 0
}
]
]
},
"insert_city_news": {
"main": [
[
{
"node": "return_save_flag",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "101e23f3-2f45-4f81-aadb-d576fd6b9f61",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-07-23T08:05:38.380Z",
"updatedAt": "2025-07-23T08:05:38.380Z",
"role": "workflow:owner",
"workflowId": "YXxHyq5d7cxKvvGu",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:05:55.413Z",
"updatedAt": "2025-07-10T02:22:46.000Z",
"id": "PK5biCTHj6VOkCXB",
"name": "test_crimemap",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as source_num from crime_mapping cm where cm.source_id ={{JSON.stringify(JSON.parse($json.body.info).Incident)}};\n\n",
"options": {}
},
"id": "f26cfa26-9d4b-462a-8949-f46f72c9c462",
"name": "is_safe_exist",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-160,
480
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\ninfo_data_list = JSON.parse($('Webhook').item.json.body.info);\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\nnews_item_data = \"\";\nzone_data = {};\nzone_data['lat'] = info_data_list.lat;\nzone_data['lon'] = info_data_list.lng;\nzone_data_str = JSON.stringify(zone_data);\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+zone_data_str+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Description+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Type_url+'\"';\n// news_item_data += ',';\n// news_item_data += '\"0\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.lang_code+'\"';\nnews_item_data += ',';\nif(!isEmptyString(info_data_list.Date)){\n news_item_data += 'STR_TO_DATE(\"'+info_data_list.Date+'\",\"%Y-%m-%d %H:%i:%s\")';\n news_item_data += ',';\n}else{\n // news_item_data += 'NOW()';\n news_item_data += 'STR_TO_DATE(NOW(),\"%Y-%m-%d %H:%i:%s\")';\n news_item_data += ',';\n};\nnews_item_data += '\"'+info_data_list.Type+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Location+'\"';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.addition+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Incident+'\"';\nnews_item_data += ')';\ncity_code_list = info_data_list.city_code.split(\",\");\nfor (let i = 0; i < city_code_list.length; i++) {\n city_code = city_code_list[i];\n item_data = \"(\";\n item_data += '\"'+city_code+'\"';\n item_data += ',';\n item_data += '@last_insert_id';\n item_data += '),';\n output_news_data_str += item_data;\n};\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['safe_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "ff6c6a22-c55f-42a9-9a33-c6ca4fefcf15",
"name": "get_safe_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
360,
360
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO crime_mapping (zone,content,icon,lang_code,event_time,event,address,addition,source_id) VALUES {{ $json.safe_data }};\n\nSET @last_insert_id = LAST_INSERT_ID();\n\nINSERT INTO city_guide (city_code, source_id)\nVALUES {{ $json.city_data }};\n\nCOMMIT;",
"options": {
"detailedOutput": true
}
},
"id": "82c92591-fd4f-49d1-9716-cefbf870f078",
"name": "insert_safe",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
620,
360
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "37fd1a36-8c69-4438-8fdc-6181956dfae3",
"leftValue": "={{ $json.source_num.toString()}}",
"rightValue": "0",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
},
{
"id": "e8a93e70-faee-4ad7-865b-c76ee1fc6270",
"leftValue": "={{ JSON.parse($('Webhook').item.json.body.info).city_code }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "f048f4c2-1b2d-4efc-9cbd-a6b7a1f0f9e9",
"name": "If_1",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
40,
480
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "37fd1a36-8c69-4438-8fdc-6181956dfae3",
"leftValue": "={{ $json.source_num.toString()}}",
"rightValue": "0",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
},
{
"id": "e8a93e70-faee-4ad7-865b-c76ee1fc6270",
"leftValue": "={{ JSON.parse($('Webhook').item.json.body.info).city_code }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "empty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "fdc5d9f4-5dbd-4d82-b33c-33d34fe8ce69",
"name": "If_2",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
360,
660
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\ninfo_data_list = JSON.parse($('Webhook').item.json.body.info);\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\nnews_item_data = \"\";\nzone_data = {};\nzone_data['lat'] = info_data_list.lat;\nzone_data['lon'] = info_data_list.lng;\nzone_data_str = JSON.stringify(zone_data);\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+zone_data_str+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Description+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Type_url+'\"';\n// news_item_data += ',';\n// news_item_data += '\"0\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.lang_code+'\"';\nnews_item_data += ',';\nif(!isEmptyString(info_data_list.Date)){\n news_item_data += 'STR_TO_DATE(\"'+info_data_list.Date+'\",\"%Y-%m-%d %H:%i:%s\")';\n news_item_data += ',';\n}else{\n // news_item_data += 'NOW()';\n news_item_data += 'STR_TO_DATE(NOW(),\"%Y-%m-%d %H:%i:%s\")';\n news_item_data += ',';\n};\nnews_item_data += '\"'+info_data_list.Type+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Location+'\"';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.addition+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Incident+'\"';\nnews_item_data += ')';\n// city_code = info_data_list.city_code;\n// item_data = \"(\";\n// item_data += '\"'+city_code+'\"';\n// item_data += ',';\n// item_data += '@last_insert_id';\n// item_data += ')';\n// output_news_data_str += item_data;\n// output_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length);\noutput_all_data['safe_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "dc1d5449-ce04-4b0b-bff5-ae28617c16e7",
"name": "get_safe_sql_no_city",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
620,
640
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO crime_mapping (zone,content,icon,lang_code,event_time,event,address,addition,source_id) VALUES {{ $json.safe_data }};\n\n-- SET @last_insert_id = LAST_INSERT_ID();\n\n-- INSERT INTO city_guide (city_code, source_id)\n-- VALUES {{ $json.city_data }};\n\nCOMMIT;",
"options": {
"detailedOutput": true
}
},
"id": "bd036425-1e86-47f0-9634-27d3d068cddc",
"name": "insert_safe_no_city",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
840,
640
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data_list = $input.all();\ninsert_id = '';\nfor(var i=0;i<result_data_list.length;i++){\n result_data = result_data_list[i].json;\n sql_val = result_data.sql;\n if(sql_val.indexOf(\"crime_mapping\")>0){\n data_temp = result_data.data;\n if(!isNullOrEmpty(data_temp)){\n insert_id = data_temp.insertId;\n break;\n }\n }\n}\nfunction isNullOrEmpty(obj) {\n return obj === null || obj === undefined || (typeof obj === 'object' && !Array.isArray(obj) && Object.keys(obj).length === 0);\n}\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all_data['insert_id'] = insert_id;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "6ce54187-c2a1-4ba0-a073-7c5b899a1e73",
"name": "return_save_flag",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
840,
360
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data_list = $input.all();\ninsert_id = '';\nfor(var i=0;i<result_data_list.length;i++){\n result_data = result_data_list[i].json;\n sql_val = result_data.sql;\n if(sql_val.indexOf(\"crime_mapping\")>0){\n data_temp = result_data.data;\n if(!isNullOrEmpty(data_temp)){\n insert_id = data_temp.insertId;\n break;\n }\n }\n}\nfunction isNullOrEmpty(obj) {\n return obj === null || obj === undefined || (typeof obj === 'object' && !Array.isArray(obj) && Object.keys(obj).length === 0);\n}\n// console.log(result_data);\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all_data['insert_id'] = insert_id;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "1089b7c5-0eb1-4f5f-a526-2925984f6ceb",
"name": "return_save_flag1",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1020,
640
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '0';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "b30b37ea-4a00-4821-b960-d786b65f50ab",
"name": "return_save_flag2",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
620,
860
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "crime/save/test",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "787a8f18-2462-4365-9ef7-95df5b635c37",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-360,
480
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"is_safe_exist": {
"main": [
[
{
"node": "If_1",
"type": "main",
"index": 0
}
]
]
},
"get_safe_sql": {
"main": [
[
{
"node": "insert_safe",
"type": "main",
"index": 0
}
]
]
},
"If_1": {
"main": [
[
{
"node": "get_safe_sql",
"type": "main",
"index": 0
}
],
[
{
"node": "If_2",
"type": "main",
"index": 0
}
]
]
},
"If_2": {
"main": [
[
{
"node": "get_safe_sql_no_city",
"type": "main",
"index": 0
}
],
[
{
"node": "return_save_flag2",
"type": "main",
"index": 0
}
]
]
},
"get_safe_sql_no_city": {
"main": [
[
{
"node": "insert_safe_no_city",
"type": "main",
"index": 0
}
]
]
},
"insert_safe": {
"main": [
[
{
"node": "return_save_flag",
"type": "main",
"index": 0
}
]
]
},
"insert_safe_no_city": {
"main": [
[
{
"node": "return_save_flag1",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_safe_exist",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "c13f0eff-0bb0-49d7-835d-648a9ed6aa66",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:05:55.421Z",
"updatedAt": "2025-02-13T05:05:55.421Z",
"role": "workflow:owner",
"workflowId": "PK5biCTHj6VOkCXB",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:16:29.165Z",
"updatedAt": "2025-05-28T07:55:12.000Z",
"id": "asu24td2qTGEEUwc",
"name": "test-guidesafe",
"active": true,
"nodes": [
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-28NY8EgqFxFM3Sg8tkrD8puN\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"query\":\"{{$json.content.replaceAll(/[ \\t\\n\\r]+/g, '')}}\",\"json_schema\":\"{{JSON.stringify($json.json_str).replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_lsfww\"\n}",
"options": {}
},
"id": "fbf4724b-3dae-4ecd-9aeb-3f3ab0e7c988",
"name": "dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
1140,
460
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select location from schedule a where a.id = {{$json.body.schedule_id}};\n",
"options": {}
},
"id": "c726c979-7ae3-46d5-8d2a-acc035b98b77",
"name": "get_location",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
400,
860
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "select id,name_cn,COALESCE('$content$', '$content$') AS content from code a where group_id = '10' and status = '0' and id in (825,826,827,828,829,830);",
"options": {}
},
"id": "c2fca027-d086-45f7-91ef-6ef4261a4469",
"name": "get_code",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
400,
340
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nconsole.log($input.item.json.body);\ninfo = $input.item.json.body.info;\noutput_info['info'] = info;\nreturn output_info;"
},
"id": "31d4c974-2c55-4ec6-8fec-6cf3da4a93e6",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
400,
620
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n let missing = '';\n if (!str.endsWith('\"}]')) {\n missing += '\"}]'\n }\n str = str+missing;\n return str;\n}\nanswer = $input.item.json.answer;\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nconsole.log(answer_str);\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nreturn answer_data;"
},
"id": "bf39b2a9-5b56-4835-a7c3-c039ef8f34ad",
"name": "get_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1340,
460
]
},
{
"parameters": {
"jsCode": "// Add a new field called 'myNewField' to the JSON of the item\noutput_all = {};\ndata_list = $input.all();\n//console.log(data_list);\ncontent_all = [];\nfor(let item_index =0; item_index < data_list.length;item_index++){\n if(item_index != data_list.length-1){\n content_all.push(data_list[item_index].json);\n }\n}\noutput_all['content'] = data_list[(data_list).length-1].json.info;\noutput_all['json_str'] = content_all;\nreturn output_all;"
},
"id": "12a60b22-2c36-4a1c-ae9c-9e56e98f8b19",
"name": "get_query_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
940,
460
]
},
{
"parameters": {},
"id": "e36e2bc3-405e-4911-b9db-c7b89182a5ed",
"name": "get_code_info",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
720,
460
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('answer' in item_data){\n content_all['answer'] = item_data['answer'];\n }else{\n content_all['location'] = item_data['location'];\n }\n}\nlocation_data_list = JSON.parse(content_all.location);\nanswer_data = content_all.answer;\noutput_all = [];\noutput_all_data = {};\noutput_all_data['answer'] = answer_data;\nlocation_data_arr = [];\nfor (let j = 0; j < location_data_list.length; j++) {\n location_data_arr.push(location_data_list[j].cityCode);\n}\noutput_all_data['city_code'] = location_data_arr;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "1a8dc7e1-9082-4159-a5cb-3de54ecd7a5a",
"name": "get_safe_guid_result",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1160,
840
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_safe_guide_source({{ JSON.stringify(JSON.stringify($json.answer)) }},{{ JSON.stringify(JSON.stringify($json.city_code)) }});",
"options": {}
},
"id": "70b5857d-2124-4350-8545-88a9ae3c9b44",
"name": "insert_city_safe_guide",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1360,
840
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "safeguide/test",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "a9f20048-fb0c-4a0f-a52f-b5329f9253b4",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-140,
620
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
},
{
"parameters": {},
"id": "77d7c4ca-c397-47cf-96ef-4f8b4c457bf2",
"name": "get_answer_location",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
940,
840
]
}
],
"connections": {
"dify": {
"main": [
[
{
"node": "get_answer",
"type": "main",
"index": 0
}
]
]
},
"get_location": {
"main": [
[
{
"node": "get_answer_location",
"type": "main",
"index": 1
}
]
]
},
"get_code": {
"main": [
[
{
"node": "get_code_info",
"type": "main",
"index": 0
}
]
]
},
"get_info": {
"main": [
[
{
"node": "get_code_info",
"type": "main",
"index": 1
}
]
]
},
"get_answer": {
"main": [
[
{
"node": "get_answer_location",
"type": "main",
"index": 0
}
]
]
},
"get_query_info": {
"main": [
[
{
"node": "dify",
"type": "main",
"index": 0
}
]
]
},
"get_code_info": {
"main": [
[
{
"node": "get_query_info",
"type": "main",
"index": 0
}
]
]
},
"get_safe_guid_result": {
"main": [
[
{
"node": "insert_city_safe_guide",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
},
{
"node": "get_code",
"type": "main",
"index": 0
},
{
"node": "get_location",
"type": "main",
"index": 0
}
]
]
},
"get_answer_location": {
"main": [
[
{
"node": "get_safe_guid_result",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "3be57b6c-ae18-4870-abad-0ef9b8f668b7",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:16:29.172Z",
"updatedAt": "2025-02-13T05:16:29.172Z",
"role": "workflow:owner",
"workflowId": "asu24td2qTGEEUwc",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-06-05T07:44:46.396Z",
"updatedAt": "2025-06-05T07:45:06.000Z",
"id": "4HGzwg4YOLxSqGnx",
"name": "test_is_exists_news",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "d1d4410d-b8db-44a9-90c1-6e026242a749",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
880,
400
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/isexistsbyid/test",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "d40d3dc8-89f2-4516-8c34-dd3bf456903e",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
620,
400
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "8ebaa2a8-845c-44d4-b64a-cae15d7608e8",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-06-05T07:44:46.408Z",
"updatedAt": "2025-06-05T07:44:46.408Z",
"role": "workflow:owner",
"workflowId": "4HGzwg4YOLxSqGnx",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-06-19T06:39:52.554Z",
"updatedAt": "2025-06-19T06:40:23.000Z",
"id": "zAVWBSbVp2Kz7PHS",
"name": "test_news_fy_label",
"active": false,
"nodes": [
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = $('Webhook').item.json.body.info.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ');\n// console.log(info);\noutput_info['text'] = info;\noutput_info['source'] = $('Webhook').item.json.body.source;\nreturn output_info;"
},
"id": "4253c107-b6a8-4277-85f8-71f06d21772e",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-400,
620
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-c06bddc665-962509615.ap-east-1.elb.amazonaws.com/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-dZITr9ks9nCa1jTnGFwefjPN\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"{{$json.source}}\"\n}",
"options": {}
},
"id": "d76cf79a-acc4-4949-b932-4788dbf3c7ea",
"name": "translate_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-200,
620
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL do_fy_label_news_source({{ JSON.stringify((JSON.stringify($json.answer)))}});",
"options": {}
},
"id": "b6b21a7d-bfe0-47ff-86df-666c24fd3e1b",
"name": "update_news_source",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
520,
440
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\nanswer = JSON.stringify($input.all()[0].json.data.outputs.answer);\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"finish_reason\"] = answer_data_json.finish_reason;\n// answer_data[\"finish_reason\"] = 'content_filter';\nanswer_data[\"answer\"] = answer_data_json.result;\n// console.log(answer_data_json.result);\nreturn answer_data;"
},
"id": "1179d6c7-2b34-4e9c-995d-b615040effe3",
"name": "get_finish_reason",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
0,
620
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.finish_reason }}",
"rightValue": "=stop",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "42dab470-e41b-44bc-bc9c-51bb446ecdb5",
"name": "is_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
200,
620
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.finish_reason }}",
"rightValue": "=content_filter",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "e15ddd39-23a1-47ee-a5af-5be9f99a42f8",
"name": "is_send_msg",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
520,
780
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\ninfo_data = $input.all()[0].json.answer;\nids_str = \"\";\nfor(var i=0;i<info_data.length;i++){\n ids_str = ids_str+info_data[i].id+\",\";\n}\nids_str = ids_str.slice(0, -1);\nfunction getFormattedDate() {\n const now = new Date();\n\n const year = now.getFullYear();\n const month = String(now.getMonth() + 1).padStart(2, '0'); // 补零\n const day = String(now.getDate()).padStart(2, '0');\n\n const hours = String(now.getHours()).padStart(2, '0');\n const minutes = String(now.getMinutes()).padStart(2, '0');\n const seconds = String(now.getSeconds()).padStart(2, '0');\n\n return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;\n}\ninfo_content = \"## 翻译异常\\n >主键ID:<font color=\\\"comment\\\">\"+ids_str+\"</font>\\n>原因:<font color=\\\"comment\\\">content_filter</font>\\n>失败时间:<font color=\\\"warning\\\"> \"+getFormattedDate()+\"</font>\\n>\";\noutput_all_data = {};\noutput_all = [];\noutput_all_data['content'] = info_content;\noutput_all.push(output_all_data);\n// console.log(output_all);\nreturn output_all;"
},
"id": "3564bd20-0061-4028-b887-0540e5604d56",
"name": "get_msg_content",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
740,
700
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-f24629df48-1909191723.ap-east-1.elb.amazonaws.com/api/v1/msg",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"content\": {{ JSON.stringify($json.content) }}\n }\n }",
"options": {}
},
"id": "718e2839-1d70-439c-b382-5bdc35de9a00",
"name": "send_msg",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
940,
700
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/fy_label/test",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "10270d2d-23e9-4135-8289-74954f8afc50",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-580,
620
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_info": {
"main": [
[
{
"node": "translate_label_dify",
"type": "main",
"index": 0
}
]
]
},
"translate_label_dify": {
"main": [
[
{
"node": "get_finish_reason",
"type": "main",
"index": 0
}
]
]
},
"get_finish_reason": {
"main": [
[
{
"node": "is_update",
"type": "main",
"index": 0
}
]
]
},
"is_update": {
"main": [
[
{
"node": "update_news_source",
"type": "main",
"index": 0
}
],
[
{
"node": "is_send_msg",
"type": "main",
"index": 0
}
]
]
},
"is_send_msg": {
"main": [
[
{
"node": "get_msg_content",
"type": "main",
"index": 0
}
]
]
},
"get_msg_content": {
"main": [
[
{
"node": "send_msg",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "47280f1b-7c0d-45a3-bb77-e52bbbf139a6",
"triggerCount": 0,
"shared": [
{
"createdAt": "2025-06-19T06:39:52.567Z",
"updatedAt": "2025-06-19T06:39:52.567Z",
"role": "workflow:owner",
"workflowId": "zAVWBSbVp2Kz7PHS",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": " <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "",
"lastName": "",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:07:52.422Z",
"updatedAt": "2025-06-13T07:27:43.000Z",
"id": "gqBaONqx9nBdgSeV",
"name": "test_qw",
"active": true,
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "qw/translate/ch/test",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "ff529c98-9a67-40fc-8900-993056d74075",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-340,
1040
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet title_info = {};\nlet summary_info = {};\ntitle = JSON.parse($input.item.json.body.info).title;\nsummary = JSON.parse($input.item.json.body.info).summary;\n// content = JSON.parse($input.item.json.body.info).content;\ntitle_info['title'] = title;\nsummary_info['summary'] = summary;\n//text_info['content'] = content;\noutput_info['title_text'] = JSON.stringify(title_info);\noutput_info['summary_text'] = JSON.stringify(summary_info);\nreturn output_info;"
},
"id": "8455f9a9-8a15-406b-8a01-0c96bb04ed3f",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-80,
1040
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-c06bddc665-962509615.ap-east-1.elb.amazonaws.com/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-fxQiMsg03GrJCtwNfLRtnD4R\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.summary_text.replaceAll(/\"/g, '\\\\\"').replaceAll(/\\\\n/g, '')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_theguardian\"\n}",
"options": {}
},
"id": "6f5fad52-de04-4faa-a400-ad725925ab79",
"name": "summary_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
180,
1160
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-c06bddc665-962509615.ap-east-1.elb.amazonaws.com/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-fxQiMsg03GrJCtwNfLRtnD4R\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.title_text.replaceAll(/\"/g, '\\\\\"').replaceAll(/\\\\n/g, '')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_theguardian\"\n}",
"options": {}
},
"id": "54a7297f-79d5-49d1-be2c-d276fe35bdae",
"name": "title_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
180,
860
]
},
{
"parameters": {},
"id": "71744dd2-f922-461d-9da2-a784013b30b6",
"name": "merge_label",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
440,
1000
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n let missing = '';\n if (!str.endsWith('\"}')) {\n missing += '\"}'\n }\n str = str+missing;\n return str;\n};\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nresult_data = $input.all();\ncontent_all = {};\nanswer_data = {};\nanswer_data_list = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n // item_data = result_data[item_index].json.data.outputs.result;\n // item_data = result_data[item_index].json.data;\n item_data = result_data[item_index].json;\n if('data' in item_data){\n item_data = item_data.data;\n }\n if('answer' in item_data){\n answer_data_str = item_data['answer'];\n answer_json_data = get_answer_data(answer_data_str);\n title = answer_json_data.title;\n summary = answer_json_data.summary;\n if(!isEmptyString(title)){\n answer_data_list['title'] = title;\n }else if(!isEmptyString(summary)){\n answer_data_list['summary'] = summary;\n }\n }\n};\nfunction get_answer_data(answer){\n answer = answer.replaceAll(/\\n/g, '').replaceAll(/%s| /g, '');\n indexes = findAllIndexes(answer,\"```\");\n answer_str = '';\n if(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n }else{\n answer_str = answer;\n }\n answer_str = answer_str.replace(/\\s+/g, '');\n answer_data_json = JSON.parse(autoCompleteJSON(answer_str));\n return answer_data_json;\n};\nanswer_data[\"answer\"] = answer_data_list;\nreturn answer_data;"
},
"id": "23c68b20-c0f9-428b-a81f-1f9c7ad6fc5f",
"name": "get_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
1000
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('answer' in item_data){\n content_all['answer'] = item_data['answer'];\n }\n};\nfunction containsChinese(str) {\n const chineseRegex = /[\\u4e00-\\u9fa5]/;\n return chineseRegex.test(str);\n};\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\n// console.log(info_data_list);\nanswer_data = content_all.answer;\nfy_title = answer_data.title;\nfy_summary = answer_data.summary;\nif(containsChinese(fy_title)){\n info_data_list['title'] = fy_title;\n}else{\n info_data_list['title'] = info_data_list.title;\n}\nif(containsChinese(fy_summary)){\n info_data_list['summary'] = fy_summary;\n}else{\n info_data_list['summary'] = info_data_list.summary;\n}\n//info_data_list['content'] = answer_data.content;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += '\"'+info_data_list.title+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.summary+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.url+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.author+'\"';\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.publish_time+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.id+'\"';\nnews_item_data += ',';\nnews_item_data += '\"4\"';\nnews_item_data += ',';\nnews_item_data += '\"zh_cn\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.news_web+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.type+'\"';\nnews_item_data += ')';\nimages_url = info_data_list.images_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '4';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "21f6d26f-bf2e-473f-846f-2a38a8904a85",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
840,
1000
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO news_source (topic,summary,source_url,author,publish_time,news_uid,status,language,news_web,news_type) VALUES {{ $json.news_data }};\n\nSET @last_insert_id = LAST_INSERT_ID();\n\nINSERT INTO news_url (url,thumbnail_url,type,status,news_id)\nVALUES {{ $json.urls_data }};\n\nCOMMIT;",
"options": {}
},
"id": "261f1c1b-da8a-4e23-ac96-76c2c0286804",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1040,
1000
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
]
]
},
"get_info": {
"main": [
[
{
"node": "summary_dify",
"type": "main",
"index": 0
},
{
"node": "title_dify",
"type": "main",
"index": 0
}
]
]
},
"summary_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 1
}
]
]
},
"title_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 0
}
]
]
},
"merge_label": {
"main": [
[
{
"node": "get_answer",
"type": "main",
"index": 0
}
]
]
},
"get_answer": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "f48a49a1-3c8c-404c-8435-e37b4869c9be",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:07:52.431Z",
"updatedAt": "2025-02-13T05:07:52.431Z",
"role": "workflow:owner",
"workflowId": "gqBaONqx9nBdgSeV",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-07-23T08:04:14.491Z",
"updatedAt": "2025-07-23T08:04:58.000Z",
"id": "gBv5NN0LfW1BTyBM",
"name": "test_report_news_is_exists",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from {{JSON.parse($json.body.info).table_name}} where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "d8326fed-9f20-4121-99cd-a84f96cc1ae7",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1040,
360
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "report/isexistsbyid/test",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "3764e57b-9dee-4cf8-ad98-a0ddccc3ef6b",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
780,
360
],
"webhookId": "807e1bd2-7166-4456-af53-bc3fea336fdc",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "91f6e129-ac7d-428f-ae53-e582b4d8edf5",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-07-23T08:04:14.499Z",
"updatedAt": "2025-07-23T08:04:14.499Z",
"role": "workflow:owner",
"workflowId": "gBv5NN0LfW1BTyBM",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-03-25T01:49:14.733Z",
"updatedAt": "2025-04-15T02:40:32.000Z",
"id": "AIoFxcSiFngLarts",
"name": "test_send_msg",
"active": false,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(1), 0) as count from (\nselect a.rw_id,screen_name,occur_date from craw_warn_log_info a where a.rw_id = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.schedule_id)) }} and a.screen_name = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.info).user_screen_name) }} and a.content like '%429%' and a.status =0 group by screen_name,occur_date) as craw_warn_info;\n",
"options": {}
},
"id": "be2e9e8e-5969-4791-9dd5-64e4383bb9bd",
"name": "is_exists_warn_by_retry",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
180,
120
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(1), 0) as count from (\nselect a.rw_id,screen_name,occur_date from craw_warn_log_info a where a.rw_id = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.schedule_id)) }} and a.screen_name = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.info).user_screen_name) }} and (a.content not like '%429%' and a.content not like '%403%' and LENGTH(TRIM(a.content))>0) and a.status =0 group by screen_name,occur_date) as craw_warn_info;\n",
"options": {}
},
"id": "524e6be9-40a9-4d67-b4d6-7bcc7e0e3f3b",
"name": "is_exists_warn_other",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
180,
380
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{$json.count}}",
"rightValue": 1,
"operator": {
"type": "number",
"operation": "gte"
}
},
{
"id": "995d3b4f-9632-485e-9367-021358d56f79",
"leftValue": "={{JSON.parse($('Webhook').all()[0].json.body.info).error_info }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "cb45ed2b-9a2a-4718-af12-30574d40a6ae",
"name": "is_send_msg_judge",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
380,
380
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{$json.count}}",
"rightValue": 3,
"operator": {
"type": "number",
"operation": "gte"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "8d355bd4-4c8b-4693-b007-f8a89c0a30b3",
"name": "is_send_msg",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
380,
120
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select a.`name` from schedule a where a.id = {{ JSON.parse($('Webhook').all()[0].json.body.schedule_id) }};\n",
"options": {}
},
"id": "b40719c4-3acc-42ba-86d4-cda1b62c3975",
"name": "get_rw_name",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
580,
240
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\ninfo_data = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = JSON.parse($('Webhook').all()[0].json.body.schedule_id);\nrw_name = $('get_rw_name').all()[0].json.name;\ninfo_content = \"## twitter采集异常\\n >ID:<font color=\\\"comment\\\">\"+schedule_id+\"</font>\\n>任务名称:<font color=\\\"comment\\\">\"+rw_name+\"</font>\\n>博主名称:<font color=\\\"comment\\\">\"+info_data.user_screen_name+\"</font>\\n>原因:<font color=\\\"comment\\\"> \"+info_data.error_info+\"</font>\\n>失败时间:<font color=\\\"warning\\\"> \"+info_data.occur_date+\"</font>\\n>详情页:<font color=\\\"comment\\\"> [http://16.162.124.172:8080/#/tasks](http://16.162.124.172:8080/#/tasks)</font>\";\noutput_all_data = {};\noutput_all = [];\noutput_all_data['content'] = info_content;\noutput_all.push(output_all_data);\n// console.log(output_all);\nreturn output_all;"
},
"id": "69b67f52-52e2-47bf-8082-1589e4e95c41",
"name": "get_msg_content",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
740,
240
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-f24629df48-1909191723.ap-east-1.elb.amazonaws.com/api/v1/msg",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"content\": {{ JSON.stringify($json.content) }}\n }\n }",
"options": {}
},
"id": "a1853b89-0f5d-4b6f-883d-20767434ff63",
"name": "send_msg",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
900,
240
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "update craw_warn_log_info set status = 1 where rw_id = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.schedule_id)) }} and screen_name = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.info).user_screen_name) }}\n",
"options": {}
},
"id": "e236a700-103d-43f3-a100-4c7a61d9a6dc",
"name": "update_warn_info",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1060,
240
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_fail_log({{ JSON.stringify($json.body.info)}},{{JSON.stringify(JSON.stringify($json.body.schedule_id)) }});\n",
"options": {}
},
"id": "dd760a0d-b700-429a-929b-8dfa73dea59c",
"name": "insert_fail_log",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-40,
260
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/fail/test2",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "582c833e-4940-462d-b804-139f9e00079b",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-200,
260
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"is_exists_warn_by_retry": {
"main": [
[
{
"node": "is_send_msg",
"type": "main",
"index": 0
}
]
]
},
"is_exists_warn_other": {
"main": [
[
{
"node": "is_send_msg_judge",
"type": "main",
"index": 0
}
]
]
},
"is_send_msg_judge": {
"main": [
[
{
"node": "get_rw_name",
"type": "main",
"index": 0
}
]
]
},
"is_send_msg": {
"main": [
[
{
"node": "get_rw_name",
"type": "main",
"index": 0
}
]
]
},
"get_rw_name": {
"main": [
[
{
"node": "get_msg_content",
"type": "main",
"index": 0
}
]
]
},
"get_msg_content": {
"main": [
[
{
"node": "send_msg",
"type": "main",
"index": 0
}
]
]
},
"send_msg": {
"main": [
[
{
"node": "update_warn_info",
"type": "main",
"index": 0
}
]
]
},
"insert_fail_log": {
"main": [
[
{
"node": "is_exists_warn_by_retry",
"type": "main",
"index": 0
},
{
"node": "is_exists_warn_other",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "insert_fail_log",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "fb141870-2295-4a62-8734-72e0187dc9b3",
"triggerCount": 0,
"shared": [
{
"createdAt": "2025-03-25T01:49:14.746Z",
"updatedAt": "2025-03-25T01:49:14.746Z",
"role": "workflow:owner",
"workflowId": "AIoFxcSiFngLarts",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": " <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "",
"lastName": "",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:03:30.843Z",
"updatedAt": "2025-02-14T07:33:56.000Z",
"id": "ZrKtEbhDs8yVpjUJ",
"name": "test_send_twitter_wrong_msg",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_fail_log({{ JSON.stringify($json.body.info)}},{{JSON.stringify(JSON.stringify($json.body.schedule_id)) }});\n",
"options": {}
},
"id": "e59344b6-70e8-4799-b4e1-6dbecdc59484",
"name": "insert_fail_log",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-660,
360
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\ninfo_data = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = JSON.parse($('Webhook').all()[0].json.body.schedule_id);\nrw_name = $('get_rw_name').all()[0].json.name;\ninfo_content = \"## twitter采集异常\\n >ID:<font color=\\\"comment\\\">\"+schedule_id+\"</font>\\n>任务名称:<font color=\\\"comment\\\">\"+rw_name+\"</font>\\n>博主名称:<font color=\\\"comment\\\">\"+info_data.user_screen_name+\"</font>\\n>原因:<font color=\\\"comment\\\"> \"+info_data.error_info+\"</font>\\n>失败时间:<font color=\\\"warning\\\"> \"+info_data.occur_date+\"</font>\\n>详情页:<font color=\\\"comment\\\"> [http://16.162.124.172:8080/#/tasks](http://16.162.124.172:8080/#/tasks)</font>\";\noutput_all_data = {};\noutput_all = [];\noutput_all_data['content'] = info_content;\noutput_all.push(output_all_data);\n// console.log(output_all);\nreturn output_all;"
},
"id": "b37c769f-7e39-446c-8206-9f046808e767",
"name": "get_msg_content",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
120,
360
]
},
{
"parameters": {
"method": "POST",
"url": "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=a71c9850-9c4c-4855-8f12-215c1badbfed",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"content\": {{ JSON.stringify($json.content) }}\n }\n }",
"options": {}
},
"id": "9507669c-8eee-4592-b1ae-19d5cb917e68",
"name": "send_msg",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
280,
360
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select a.`name` from schedule a where a.id = {{ JSON.parse($('Webhook').all()[0].json.body.schedule_id) }};\n",
"options": {}
},
"id": "4ffbc856-f289-44d8-a563-c372ada8ab66",
"name": "get_rw_name",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-40,
360
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "update craw_warn_log_info set status = 1 where rw_id = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.schedule_id)) }} and screen_name = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.info).user_screen_name) }}\n",
"options": {}
},
"id": "3387d853-b3f6-46c5-b48b-27648611841c",
"name": "update_warn_info",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
440,
360
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(1), 0) as count from (\nselect a.rw_id,screen_name,occur_date from craw_warn_log_info a where a.rw_id = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.schedule_id)) }} and a.screen_name = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.info).user_screen_name) }} and a.content like '%429%' and a.status =0 group by screen_name,occur_date) as craw_warn_info;\n",
"options": {}
},
"id": "f94cb3ef-b662-4e8a-bb07-4372b7e39088",
"name": "is_exists_warn_by_retry",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-440,
220
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(1), 0) as count from (\nselect a.rw_id,screen_name,occur_date from craw_warn_log_info a where a.rw_id = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.schedule_id)) }} and a.screen_name = {{JSON.stringify(JSON.parse($('Webhook').all()[0].json.body.info).user_screen_name) }} and (a.content not like '%429%' and a.content not like '%403%') and a.status =0 group by screen_name,occur_date) as craw_warn_info;\n",
"options": {}
},
"id": "3bb73703-c46b-41be-8237-16e46f8e9c1a",
"name": "is_exists_warn_other",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-440,
480
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{$json.count}}",
"rightValue": 1,
"operator": {
"type": "number",
"operation": "gte"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "2eb33ef9-99ed-4eb6-aff7-089db98b05e4",
"name": "is_send_msg_judge",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-240,
480
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{$json.count}}",
"rightValue": 3,
"operator": {
"type": "number",
"operation": "gte"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "0e74e010-e212-4d4f-ba8e-a0bdb8b8fa07",
"name": "is_send_msg",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-240,
220
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/fail/test",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "8679281d-cd04-4c32-a53d-ed6b084d6479",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-820,
360
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"insert_fail_log": {
"main": [
[
{
"node": "is_exists_warn_by_retry",
"type": "main",
"index": 0
},
{
"node": "is_exists_warn_other",
"type": "main",
"index": 0
}
]
]
},
"get_msg_content": {
"main": [
[
{
"node": "send_msg",
"type": "main",
"index": 0
}
]
]
},
"send_msg": {
"main": [
[
{
"node": "update_warn_info",
"type": "main",
"index": 0
}
]
]
},
"get_rw_name": {
"main": [
[
{
"node": "get_msg_content",
"type": "main",
"index": 0
}
]
]
},
"is_exists_warn_by_retry": {
"main": [
[
{
"node": "is_send_msg",
"type": "main",
"index": 0
}
]
]
},
"is_exists_warn_other": {
"main": [
[
{
"node": "is_send_msg_judge",
"type": "main",
"index": 0
}
]
]
},
"is_send_msg_judge": {
"main": [
[
{
"node": "get_rw_name",
"type": "main",
"index": 0
}
]
]
},
"is_send_msg": {
"main": [
[
{
"node": "get_rw_name",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "insert_fail_log",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "9fd2ea41-c2b3-4a6e-9523-1e3098eb4ba8",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:03:30.851Z",
"updatedAt": "2025-02-13T05:03:30.851Z",
"role": "workflow:owner",
"workflowId": "ZrKtEbhDs8yVpjUJ",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": " <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "",
"lastName": "",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:09:56.575Z",
"updatedAt": "2025-02-13T05:10:04.000Z",
"id": "eRywiclDmLD3rzji",
"name": "test_theguardian",
"active": true,
"nodes": [
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KRXKS2lXohYjnIKmuYxSncem\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"').replaceAll(/\\\\n/g, '')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_theguardian\"\n}",
"options": {}
},
"id": "183ec461-7b39-48ef-a6bb-98de5fdfe11f",
"name": "dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
900,
260
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ntitle = JSON.parse($input.item.json.body.info).title;\ncontent = JSON.parse($input.item.json.body.info).content;\ntext_info['title'] = title;\n//text_info['content'] = content;\noutput_info['text'] = JSON.stringify(text_info);\nreturn output_info;"
},
"id": "bb8c4f66-723d-4b4e-9202-e1ffc934beb8",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
260
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n let missing = '';\n if (!str.endsWith('\"}')) {\n missing += '\"}'\n }\n str = str+missing;\n return str;\n}\nanswer = $input.item.json.answer;\nanswer = answer.replaceAll(/\\n/g, '').replaceAll(/%s| /g, '');\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nreturn answer_data;"
},
"id": "28e1681a-c530-4c04-a07f-c76a09df7592",
"name": "get_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1180,
260
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO news_source (topic,content,source_url,news_uid,status,language,snapshot,news_web,news_type) VALUES {{ $json.news_data }};\n\nSET @last_insert_id = LAST_INSERT_ID();\n\nINSERT INTO news_url (url, type,news_id)\nVALUES {{ $json.urls_data }};\n\nCOMMIT;",
"options": {}
},
"id": "94ddd8f2-a743-4bd5-a650-8517bf3769cc",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1700,
260
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('answer' in item_data){\n content_all['answer'] = item_data['answer'];\n }\n}\n//console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').item.json.body.info);\nanswer_data = content_all.answer;\ninfo_data_list['title'] = answer_data.title;\n//info_data_list['content'] = answer_data.content;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += '\"'+info_data_list.title+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.content+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.url+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.id+'\"';\nnews_item_data += ',';\nnews_item_data += '\"4\"';\nnews_item_data += ',';\nnews_item_data += '\"zh_cn\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.html_url+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.news_web+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.type+'\"';\nnews_item_data += ')';\nimages_url = info_data_list.images_url;\nfor (let i = 0; i < images_url.length; i++) {\n image_url = images_url[i];\n image_item_data = \"(\";\n image_item_data += '\"'+image_url+'\"';\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n}\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','',''),\"\n}\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "799360b0-2c9b-4c38-b14b-b0368add48e7",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1440,
260
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "theguardian/translate/ch/test",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "5420669a-71e4-4386-8d42-2567613ea3b5",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
380,
260
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "1fHtEpWRIg2mFYBe",
"name": "Header Auth account"
}
}
}
],
"connections": {
"dify": {
"main": [
[
{
"node": "get_answer",
"type": "main",
"index": 0
}
]
]
},
"get_info": {
"main": [
[
{
"node": "dify",
"type": "main",
"index": 0
}
]
]
},
"get_answer": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": null,
"pinData": null,
"versionId": "a5e7ceea-f48f-4447-b656-c2fafd83f2e6",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:09:56.588Z",
"updatedAt": "2025-02-13T05:09:56.588Z",
"role": "workflow:owner",
"workflowId": "eRywiclDmLD3rzji",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-06-05T07:41:12.133Z",
"updatedAt": "2025-06-06T05:28:19.000Z",
"id": "C9tGGg6ONepVA1tR",
"name": "test_tw_search_by_crime_keyword",
"active": true,
"nodes": [
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = JSON.parse($('Webhook').item.json.body.info).full_text.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ').replaceAll(\"\\\"\", '” ');\n// console.log(info);\nuser_id = JSON.parse($('Webhook').item.json.body.info).id;\ntext_info['full_text'] = info;\noutput_info['text'] = JSON.stringify(text_info);\noutput_info['msg_info'] = info;\noutput_info['user_id'] = user_id;\nreturn output_info;"
},
"id": "d2e7ca4b-b726-42cc-98e7-848fdc9bf345",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1100,
500
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n",
"options": {}
},
"id": "9c9f15ec-9072-4c1d-9c04-c4fc9534e450",
"name": "update_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1100,
780
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "b1fa0c29-891e-4c29-b5a0-e4d81c341009",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
700,
660
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }} and news_type = 1;\n",
"options": {}
},
"id": "2bb751ff-1887-43de-8866-3dbdd8875f97",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
460,
660
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL record_craw_zh_counts({{JSON.stringify(($json.body.info.parseJson().removeField(\"full_text\").toJsonString()))}},{{JSON.stringify(JSON.stringify($json.body.schedule_id)) }});",
"options": {}
},
"id": "c9d2b41a-88ff-4df9-a5de-faede6638fa6",
"name": "record_zh_info",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
460,
400
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source_keyword({{ (JSON.stringify($json.data))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "79ed1c75-55d9-4323-8981-49b4c5b97491",
"name": "insert_news_source",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1580,
500
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\n// console.log(result_data);\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nfull_text_origial = info_data_list.full_text.replace(/https:\\/\\/[^\\s]+/g, '');\n// full_text_origial = result_data[0].json.msg_info;\ninfo_data_list['full_text'] = full_text_origial\ninfo_data_list['full_text_ch'] = full_text_origial;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\nlocation_data = info_data_list.location;\nif(isEmptyString(location_data)){\n location_data_arr = \"\";\n}else{\n location_data_arr = JSON.parse(info_data_list.location);\n}\nfull_text_new = info_data_list.full_text.replace(/'/g, \"\").replace(/\"/g, \"\");\nfull_text_ch_new = info_data_list.full_text_ch.replace(/'/g, \"\").replace(/\"/g, \"\");\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+full_text_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+full_text_ch_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.screen_name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.profile_image_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.favourite_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.retweet_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.view_count+\"'\";\nnews_item_data += ',';\nif(isEmptyString(location_data_arr)){\n news_item_data += \"''\";\n news_item_data += ',';\n news_item_data += \"''\";\n news_item_data += ',';\n}else{\n news_item_data += \"'\"+location_data_arr[0]+\"'\";\n news_item_data += ',';\n news_item_data += \"'\"+location_data_arr[1]+\"'\";\n news_item_data += ',';\n}\nnews_item_data += \"'zh_cn'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.created_at+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'twitter_search'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.news_type+\"'\";\nnews_item_data += ')';\n// city_code = info_data_list.city_code;\n// item_data = \"(\";\n// item_data += \"'\"+city_code+\"'\";\n// item_data += ',';\n// item_data += '@last_insert_id';\n// item_data += '),';\n// output_news_data_str += item_data;\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '4';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '4';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\n// output_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all_data_temp['label_data'] = [];\noutput_all_data_temp['artificial_label_data'] = [];\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "88a9e29b-1a44-4aab-abfa-d89d9c5504ec",
"name": "get_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1340,
500
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/keyword/test",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "add5c836-bfff-4c3a-af60-9ffd32cea93e",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
200,
660
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_info": {
"main": [
[
{
"node": "get_news_sql",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
],
[
{
"node": "update_city_news",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"get_news_sql": {
"main": [
[
{
"node": "insert_news_source",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
},
{
"node": "record_zh_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "9956940f-8fac-42ba-8585-edfffc7144cc",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-06-05T07:41:12.145Z",
"updatedAt": "2025-06-05T07:41:12.145Z",
"role": "workflow:owner",
"workflowId": "C9tGGg6ONepVA1tR",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:12:09.233Z",
"updatedAt": "2025-02-13T05:12:28.000Z",
"id": "ayzMOr3NuwyzSudK",
"name": "test_twitter",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select location from schedule a where a.id = {{$('Webhook').item.json.body.schedule_id}};\n",
"options": {}
},
"id": "6e86c67c-9c7a-4c51-9785-23db8d4b1e45",
"name": "get_location",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
160,
840
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = JSON.parse($('Webhook').item.json.body.info).full_text.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ').replaceAll(\"\\\"\", '” ');\nconsole.log(info);\nuser_id = JSON.parse($('Webhook').item.json.body.info).id;\ntext_info['full_text'] = info;\noutput_info['text'] = JSON.stringify(text_info);\noutput_info['msg_info'] = info;\noutput_info['user_id'] = user_id;\nreturn output_info;"
},
"id": "b0d081ec-6b7a-4191-bf79-d8b929000012",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-220,
360
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source({{ (JSON.stringify($json.data))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "d2a882c0-83cb-499b-bfb9-fc186ee42491",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
920,
820
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('location' in item_data){\n content_all['location'] = item_data['location'];\n }else if('label_data' in item_data){\n content_all['label'] = item_data['label_data'];\n }else if('artificial_label_data' in item_data){\n content_all['artificial_label'] = item_data['artificial_label_data'];\n }\n};\nconsole.log(content_all);\nlocation_data_list = JSON.parse(content_all.location);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nlabel_data_list = content_all.label;\nartificial_label_data_list = content_all.artificial_label;\nif(artificial_label_data_list.length>0 && location_data_list.length>0){\n artificial_label_data_list[0]['city_code'] = location_data_list[0].cityCode;\n}\ninfo_data_list['full_text'] = info_data_list.full_text.replace(/https:\\/\\/[^\\s]+/g, '');\ntranster_answer_data = $('get_transter_answer').all()[0].json.answer.full_text;\ninfo_data_list['full_text_ch'] = transter_answer_data;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\noutput_news_label_data_str = \"\";\nfull_text_new = info_data_list.full_text.replace(/'/g, \"\").replace(/\"/g, \"\");\nfull_text_ch_new = info_data_list.full_text_ch.replace(/'/g, \"\").replace(/\"/g, \"\");\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+full_text_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+full_text_ch_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.screen_name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.profile_image_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.favourite_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.retweet_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.view_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'zh_cn'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.created_at+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'twitter'\";\nnews_item_data += ',';\nnews_item_data += \"'1'\";\nnews_item_data += ')';\nfor (let i = 0; i < location_data_list.length; i++) {\n city_code = location_data_list[i].cityCode;\n item_data = \"(\";\n item_data += \"'\"+city_code+\"'\";\n item_data += ',';\n item_data += '@last_insert_id';\n item_data += '),';\n output_news_data_str += item_data;\n};\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all_data_temp['label_data'] = label_data_list;\noutput_all_data_temp['artificial_label_data'] = artificial_label_data_list;\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "074bdda0-c3e3-4f51-b6bc-532c742292cf",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
660,
820
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n",
"options": {}
},
"id": "85817c35-b2ce-4872-8479-4548a5e2b276",
"name": "update_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
160,
1300
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "dc70a167-aef7-4ade-85c6-a26cb2b290e7",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-500,
860
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "ceb1f94f-10dc-47f2-b6fe-c84e2c98bc44",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-740,
860
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KRXKS2lXohYjnIKmuYxSncem\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "6145fdcb-90cc-40a6-9977-5ffa984fceb1",
"name": "translate_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-40,
360
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\nfunction isEmpty(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value) {\n return true;\n }\n return false;\n};\nlabel_data_list = [];\nartificial_label_data_list = [];\nlabel_data_arr = $input.all();\nlabel_result_list = [];\nartificial_label_result_list = [];\nfor(var label_index=0;label_index<label_data_arr.length;label_index++){\n label_data_temp = label_data_arr[label_index];\n workflow_id = label_data_temp.json.data.workflow_id;\n label_data_output_list = label_data_temp.json.data.outputs;\n if(workflow_id == '767511d7-ccf6-42c1-a42e-b2c14959c147'){\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n for (let i = 0; i < label_result.length; i++) {\n label_result_list.push(label_result[i]);\n }\n }\n }else{\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n let label_index_temp = 0;\n for (let i = 0; i < label_result.length&&label_index_temp<1; i++) {\n artificial_label_result_list.push(label_result[i]);\n label_index_temp += 1;\n }\n } \n }\n};\n// console.log(label_result_list);\nfor (let i = 0; i < label_result_list.length; i++) {\n label_code_score = {};\n label_code = label_result_list[i].code;\n label_score = label_result_list[i].score;\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['score'] = label_score;\n label_data_list.push(label_code_score);\n }\n};\nfor (let i = 0; i < artificial_label_result_list.length; i++) {\n label_code_score = {};\n label_code = artificial_label_result_list[i].code;\n label_name = artificial_label_result_list[i].name;\n label_score = artificial_label_result_list[i].score;\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['name'] = label_name;\n label_code_score['score'] = label_score;\n artificial_label_data_list.push(label_code_score);\n }\n};\nlabel_data_list_2 = [];\nlabel_data_json = {};\nartificial_label_data_json = {};\nlabel_data_json[\"label_data\"] = label_data_list;\nartificial_label_data_json[\"artificial_label_data\"] = artificial_label_data_list;\n// console.log(label_data_json);\nlabel_data_list_2.push(label_data_json);\nlabel_data_list_2.push(artificial_label_data_json);\nreturn label_data_list_2;"
},
"id": "8d24769d-b172-4eb6-94ed-b26d393ca586",
"name": "get_label_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
920,
480
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\nanswer =$input.all()[0].json.answer;\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nreturn answer_data;"
},
"id": "d8a587f3-5d55-4619-837d-41f0f24a94b0",
"name": "get_transter_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
140,
360
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-SRHXAMF0iYxuCJD5cnHYgtJZ\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$('get_info').item.json.msg_info.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "12c6c784-94fc-4c8b-9244-1366ce52e2af",
"name": "natural_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
400,
480
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-HCbsiZmUCzP8Vdqb2meKXQSb\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$json.answer.full_text.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "876be9b2-24ea-4166-bdcc-6acaed3f9697",
"name": "artificial_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
400,
280
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/translate/ch/test",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "9eaddc81-9c24-4aef-9ce8-7e4542b55b8b",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-1000,
860
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "1fHtEpWRIg2mFYBe",
"name": "Header Auth account"
}
}
},
{
"parameters": {},
"id": "d8e717bd-263c-4ab3-9b55-c644b99a81ee",
"name": "merge_label",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
620,
380
]
},
{
"parameters": {},
"id": "23a95c09-ccca-439a-b7d2-e6b3c99e4d42",
"name": "get_answer_location",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
400,
820
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select location from schedule a where a.id = {{$('Webhook').item.json.body.schedule_id}};\n",
"options": {}
},
"id": "2c58ed5a-e5b6-4b29-9d54-eb3ff6cdbf21",
"name": "get_city_code",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
160,
1080
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('location' in item_data){\n content_all['location'] = item_data['location'];\n }\n};\nlocation_data_list = JSON.parse(content_all.location);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\noutput_news_data_str = '';\noutput_all_data = {};\noutput_all = [];\noutput_city_code_list = [];\nfor (let i = 0; i < location_data_list.length; i++) {\n city_code = location_data_list[i].cityCode;\n output_city_code_list.push(city_code);\n};\noutput_all_data['city_code'] = output_city_code_list;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all.push(output_all_data);\nconsole.log(output_all);\nreturn output_all;"
},
"id": "20594f0b-7af8-4009-b86b-8e5850947c7a",
"name": "get_city_code_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
400,
1080
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_city({{ JSON.stringify(JSON.stringify($json.city_code))}},{{ JSON.stringify(JSON.stringify($json.news_id)) }});",
"options": {}
},
"id": "8417d3d8-1afb-4c15-9bd5-68a9ceeba588",
"name": "insert_city_data",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
660,
1080
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
}
],
"connections": {
"get_location": {
"main": [
[
{
"node": "get_answer_location",
"type": "main",
"index": 1
}
]
]
},
"get_info": {
"main": [
[
{
"node": "translate_dify",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
},
{
"node": "get_location",
"type": "main",
"index": 0
}
],
[
{
"node": "get_city_code",
"type": "main",
"index": 0
},
{
"node": "update_city_news",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"translate_dify": {
"main": [
[
{
"node": "get_transter_answer",
"type": "main",
"index": 0
}
]
]
},
"get_label_answer": {
"main": [
[
{
"node": "get_answer_location",
"type": "main",
"index": 0
}
]
]
},
"get_transter_answer": {
"main": [
[
{
"node": "artificial_label_dify",
"type": "main",
"index": 0
},
{
"node": "natural_label_dify",
"type": "main",
"index": 0
}
]
]
},
"natural_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 1
}
]
]
},
"artificial_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
},
"merge_label": {
"main": [
[
{
"node": "get_label_answer",
"type": "main",
"index": 0
}
]
]
},
"get_answer_location": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"get_city_code": {
"main": [
[
{
"node": "get_city_code_info",
"type": "main",
"index": 0
}
]
]
},
"get_city_code_info": {
"main": [
[
{
"node": "insert_city_data",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": null,
"pinData": null,
"versionId": "f445181e-bbd7-4bb6-998a-4a31f0638554",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:12:09.240Z",
"updatedAt": "2025-02-13T05:12:09.240Z",
"role": "workflow:owner",
"workflowId": "ayzMOr3NuwyzSudK",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:14:35.312Z",
"updatedAt": "2025-04-07T09:04:13.000Z",
"id": "57aCJDSSJypES4rd",
"name": "test_twitter_search",
"active": true,
"nodes": [
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = JSON.parse($('Webhook').item.json.body.info).full_text.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ').replaceAll(\"\\\"\", '” ');\nconsole.log(info);\nuser_id = JSON.parse($('Webhook').item.json.body.info).id;\ntext_info['full_text'] = info;\noutput_info['text'] = JSON.stringify(text_info);\noutput_info['msg_info'] = info;\noutput_info['user_id'] = user_id;\nreturn output_info;"
},
"id": "7a5067f2-ec56-49d0-bc69-570b4f1f6ea4",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-180,
340
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source({{ (JSON.stringify($json.data))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "6facef1a-0979-4f4b-82e5-9c848e843990",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
960,
800
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('label_data' in item_data){\n content_all['label'] = item_data['label_data'];\n }else if('artificial_label_data' in item_data){\n content_all['artificial_label'] = item_data['artificial_label_data'];\n }\n};\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nlabel_data_list = content_all.label;\nartificial_label_data_list = content_all.artificial_label;\nif(artificial_label_data_list.length>0){\n artificial_label_data_list[0]['city_code'] = info_data_list.city_code;\n}\ninfo_data_list['full_text'] = info_data_list.full_text.replace(/https:\\/\\/[^\\s]+/g, '');\ntranster_answer_data = $('get_transter_answer').all()[0].json.answer.full_text;\ninfo_data_list['full_text_ch'] = transter_answer_data;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\noutput_news_label_data_str = \"\";\nfull_text_new = info_data_list.full_text.replace(/'/g, \"\").replace(/\"/g, \"\");\nfull_text_ch_new = info_data_list.full_text_ch.replace(/'/g, \"\").replace(/\"/g, \"\");\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+full_text_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+full_text_ch_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.screen_name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.profile_image_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.favourite_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.retweet_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.view_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'zh_cn'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.created_at+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'twitter_search'\";\nnews_item_data += ',';\nnews_item_data += \"'1'\";\nnews_item_data += ')';\ncity_code = info_data_list.city_code;\nitem_data = \"(\";\nitem_data += \"'\"+city_code+\"'\";\nitem_data += ',';\nitem_data += '@last_insert_id';\nitem_data += '),';\noutput_news_data_str += item_data;\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all_data_temp['label_data'] = label_data_list;\noutput_all_data_temp['artificial_label_data'] = artificial_label_data_list;\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "4b3522f1-1065-44de-81eb-d46f8d782941",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
700,
800
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n",
"options": {}
},
"id": "d1bd9731-a2a3-4b4f-9bb6-fa4e009c187e",
"name": "update_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
440,
1340
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "4d66af0e-86b3-4fe1-bb69-aafa0ff2ff15",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-460,
840
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "b6b4b3d8-f0a7-405d-b714-a2f2a94ccbd7",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-700,
840
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KRXKS2lXohYjnIKmuYxSncem\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "2670f32e-a915-4ff3-96af-2d20f6ec54ea",
"name": "translate_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
0,
340
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\nfunction isEmpty(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value) {\n return true;\n }\n return false;\n};\nlabel_data_list = [];\nartificial_label_data_list = [];\nlabel_data_arr = $input.all();\nlabel_result_list = [];\nartificial_label_result_list = [];\nfor(var label_index=0;label_index<label_data_arr.length;label_index++){\n label_data_temp = label_data_arr[label_index];\n workflow_id = label_data_temp.json.data.workflow_id;\n label_data_output_list = label_data_temp.json.data.outputs;\n if(workflow_id == '767511d7-ccf6-42c1-a42e-b2c14959c147'){\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n for (let i = 0; i < label_result.length; i++) {\n label_result_list.push(label_result[i]);\n }\n }\n }else{\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n let label_index_temp = 0;\n for (let i = 0; i < label_result.length&&label_index_temp<1; i++) {\n artificial_label_result_list.push(label_result[i]);\n label_index_temp += 1;\n }\n } \n }\n};\n// console.log(label_result_list);\nfor (let i = 0; i < label_result_list.length; i++) {\n label_code_score = {};\n label_code = label_result_list[i].code;\n label_score = label_result_list[i].score;\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['score'] = label_score;\n label_data_list.push(label_code_score);\n }\n};\nfor (let i = 0; i < artificial_label_result_list.length; i++) {\n label_code_score = {};\n label_code = artificial_label_result_list[i].code;\n label_name = artificial_label_result_list[i].name;\n label_score = artificial_label_result_list[i].score;\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['name'] = label_name;\n label_code_score['score'] = label_score;\n artificial_label_data_list.push(label_code_score);\n }\n};\nlabel_data_list_2 = [];\nlabel_data_json = {};\nartificial_label_data_json = {};\nlabel_data_json[\"label_data\"] = label_data_list;\nartificial_label_data_json[\"artificial_label_data\"] = artificial_label_data_list;\n// console.log(label_data_json);\nlabel_data_list_2.push(label_data_json);\nlabel_data_list_2.push(artificial_label_data_json);\nreturn label_data_list_2;"
},
"id": "26f5df11-a0fe-4ce7-a4fc-7ea44dd90e34",
"name": "get_label_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
960,
460
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\nanswer =$input.all()[0].json.answer;\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nreturn answer_data;"
},
"id": "740b6905-747f-4ada-b0e9-9c29fc38946f",
"name": "get_transter_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
180,
340
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-SpF4P9z8VEGuskQp1Dy71aqB\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$json.answer.full_text.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "a0dbb20a-e207-499a-a279-2d4d44f28011",
"name": "artificial_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
440,
260
]
},
{
"parameters": {},
"id": "58945e62-7c70-4d62-9f25-e6cd7a57c6db",
"name": "merge_label",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
660,
360
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\noutput_news_data_str = '';\noutput_all_data = {};\noutput_all = [];\noutput_city_code_list = [];\ncity_code = info_data_list.city_code;\noutput_city_code_list.push(city_code);\noutput_all_data['city_code'] = output_city_code_list;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all.push(output_all_data);\nconsole.log(output_all);\nreturn output_all;"
},
"id": "6ddffe3a-2c35-4174-be34-63dbb38c5f67",
"name": "get_city_code_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
440,
1060
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_city({{ JSON.stringify(JSON.stringify($json.city_code))}},{{ JSON.stringify(JSON.stringify($json.news_id)) }});",
"options": {}
},
"id": "f8170c6b-670a-4fc1-abe6-fb897fc5473a",
"name": "insert_city_data",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
700,
1060
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {},
"id": "5844342a-77cd-4122-b774-4a47e0447a2b",
"name": "get_answer_location",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
440,
800
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL record_craw_zh_counts({{JSON.stringify(($json.body.info.parseJson().removeField(\"full_text\").toJsonString()))}},{{JSON.stringify(JSON.stringify($json.body.schedule_id)) }});\n",
"options": {}
},
"id": "2fb89b73-5d6b-430e-957e-e0c70b004239",
"name": "record_zh_info",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-700,
460
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/test",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "91618bb8-9952-4c09-bd11-ecc07632fd5f",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-960,
840
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KNq0O8kENP4ITqSmqHQ0IzAt\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$('get_info').item.json.msg_info.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "f28aa84a-94e8-4c05-abd3-8fe54ae1a2b7",
"name": "news_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
440,
460
]
}
],
"connections": {
"get_info": {
"main": [
[
{
"node": "translate_dify",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
},
{
"node": "get_answer_location",
"type": "main",
"index": 1
}
],
[
{
"node": "update_city_news",
"type": "main",
"index": 0
},
{
"node": "get_city_code_info",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"translate_dify": {
"main": [
[
{
"node": "get_transter_answer",
"type": "main",
"index": 0
}
]
]
},
"get_label_answer": {
"main": [
[
{
"node": "get_answer_location",
"type": "main",
"index": 0
}
]
]
},
"get_transter_answer": {
"main": [
[
{
"node": "artificial_label_dify",
"type": "main",
"index": 0
},
{
"node": "news_label_dify",
"type": "main",
"index": 0
}
]
]
},
"artificial_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 0
}
]
]
},
"merge_label": {
"main": [
[
{
"node": "get_label_answer",
"type": "main",
"index": 0
}
]
]
},
"get_city_code_info": {
"main": [
[
{
"node": "insert_city_data",
"type": "main",
"index": 0
}
]
]
},
"get_answer_location": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
},
{
"node": "record_zh_info",
"type": "main",
"index": 0
}
]
]
},
"news_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 1
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "bcdf06d2-8e75-4cd6-a317-b6f35e317800",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:14:35.323Z",
"updatedAt": "2025-02-13T05:14:35.323Z",
"role": "workflow:owner",
"workflowId": "57aCJDSSJypES4rd",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-07-23T08:01:00.152Z",
"updatedAt": "2025-07-29T08:59:10.000Z",
"id": "0JTA9HrjBatVJCMu",
"name": "test_warn_report_news",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from report_news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).news_uid) }};\n",
"options": {}
},
"id": "10cc4c7c-c2a5-4adc-b3de-3d07dc86577d",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
200,
660
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "2b55ed6c-9ed7-4852-994d-d7d051b0eb1d",
"name": "is_save",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
420,
660
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\noutput_all = [];\noutput_all_data = {};\noutput_news_url_data_str = \"\";\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+info_data_list.title+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.content+\"'\";\nnews_item_data += ',';\nif(isEmptyString(info_data_list.author)){\n news_item_data += null;\n}else{\n news_item_data += \"'\"+info_data_list.author+\"'\";\n}\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.source_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.status+\"'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.publish_time+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\n// news_item_data += \"'\"+info_data_list.source_content+\"'\";\n// news_item_data += ',';\nnews_item_data += \"'\"+info_data_list.news_web+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.news_uid+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.country+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.area+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.city+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.rank+\"'\";\nnews_item_data += ',';\nif(isEmptyString(info_data_list.schedule_id)){\n news_item_data += null;\n}else{\n news_item_data += \"'\"+info_data_list.schedule_id+\"'\";\n}\nnews_item_data += ')';\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '4';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '4';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\n\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "0d35aa6b-5431-4933-9589-ecf354210b99",
"name": "get_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
720,
500
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '0';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "94995dba-798a-461c-8678-b21e65eeeee6",
"name": "return_result",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
720,
760
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "b6979837-7bea-4de8-acd0-8ea607d4774c",
"name": "return_save_flag",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1420,
380
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ JSON.parse($json.data).urls_data.toString() }}",
"rightValue": "=('','','','')",
"operator": {
"type": "string",
"operation": "notEquals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "1acd863b-74a6-4ccb-9cf3-d92a3c1e4339",
"name": "is_url",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
940,
500
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO report_news_source (title,content,author,source_url,status,publish_time,news_web,news_uid,country_name,overseas,city,score,schedule_id) VALUES {{ JSON.parse($json.data).news_data }};\n\n-- SET @last_insert_id = LAST_INSERT_ID();\n-- INSERT INTO news_url (url,thumbnail_url,type,status,news_id) VALUES {{ JSON.parse($json.data).urls_data }};\n\nCOMMIT;",
"options": {}
},
"id": "7093c66c-7e14-4bf2-bc5a-c75f6a14ff5b",
"name": "save_news_url",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1200,
380
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO report_news_source (title,content,author,source_url,status,publish_time,news_web,news_uid,country_name,overseas,city,score,schedule_id) VALUES {{ JSON.parse($json.data).news_data }};\n\nCOMMIT;",
"options": {}
},
"id": "32d7fe48-523a-460e-b467-a678368b98a2",
"name": "save_news_no_url",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1200,
620
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "a2209bc0-4e55-4bd1-a632-2be323510751",
"name": "return_save_flag_2",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1420,
620
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "warn/wjbwlb/save/test",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "8b18e5f6-9ff2-4e84-b540-cfb471ab0f28",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
0,
660
],
"webhookId": "b451c79d-f716-44c4-94fb-322b49a1f675",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"is_exists_news": {
"main": [
[
{
"node": "is_save",
"type": "main",
"index": 0
}
]
]
},
"is_save": {
"main": [
[
{
"node": "get_news_sql",
"type": "main",
"index": 0
}
],
[
{
"node": "return_result",
"type": "main",
"index": 0
}
]
]
},
"get_news_sql": {
"main": [
[
{
"node": "is_url",
"type": "main",
"index": 0
}
]
]
},
"is_url": {
"main": [
[
{
"node": "save_news_url",
"type": "main",
"index": 0
}
],
[
{
"node": "save_news_no_url",
"type": "main",
"index": 0
}
]
]
},
"save_news_url": {
"main": [
[
{
"node": "return_save_flag",
"type": "main",
"index": 0
}
]
]
},
"save_news_no_url": {
"main": [
[
{
"node": "return_save_flag_2",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "04125b6e-0c77-4984-86c3-47af32d19c8a",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-07-23T08:01:00.165Z",
"updatedAt": "2025-07-23T08:01:00.165Z",
"role": "workflow:owner",
"workflowId": "0JTA9HrjBatVJCMu",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-15T02:43:53.943Z",
"updatedAt": "2025-04-16T02:11:44.000Z",
"id": "DcMIHShxOTGHW0Ku",
"name": "tw_account_exception_msg",
"active": true,
"nodes": [
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\ninfo_data = JSON.parse($('Webhook').all()[0].json.body.info);\ninfo_content = \"## twitter账号异常\\n >账号名:<font color=\\\"comment\\\">\"+info_data.username+\"</font>\\n>原因:<font color=\\\"comment\\\"> \"+info_data.fail_msg+\"</font>\\n>失败时间:<font color=\\\"warning\\\"> \"+info_data.update_at+\"</font>\\n>\";\noutput_all_data = {};\noutput_all = [];\noutput_all_data['content'] = info_content;\noutput_all.push(output_all_data);\n// console.log(output_all);\nreturn output_all;"
},
"id": "06c12c14-bf02-4b24-b0f2-c9bf7d2f2a8d",
"name": "get_msg_content",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
720,
380
]
},
{
"parameters": {
"method": "POST",
"url": "http://k8s-security-ingresss-f24629df48-1909191723.ap-east-1.elb.amazonaws.com/api/v1/msg",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"msgtype\": \"markdown\",\n \"markdown\": {\n \"content\": {{ JSON.stringify($json.content) }}\n }\n }",
"options": {}
},
"id": "c41cba3c-f995-432a-b116-9f25df7f9a59",
"name": "send_msg",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
980,
380
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/account/msg",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "eb363c46-1b55-46a7-920a-48cafbfdddda",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
400,
380
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_msg_content": {
"main": [
[
{
"node": "send_msg",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "get_msg_content",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "cc451c97-b275-487a-8886-c75d3ff9efe0",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-15T02:43:53.957Z",
"updatedAt": "2025-04-15T02:43:53.957Z",
"role": "workflow:owner",
"workflowId": "DcMIHShxOTGHW0Ku",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": " <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "",
"lastName": "",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-05-06T06:19:14.643Z",
"updatedAt": "2025-06-05T06:44:31.000Z",
"id": "NVlFW3egbrGCTDLb",
"name": "tw_search_by_keyword",
"active": true,
"nodes": [
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = JSON.parse($('Webhook').item.json.body.info).full_text.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ').replaceAll(\"\\\"\", '” ');\n// console.log(info);\nuser_id = JSON.parse($('Webhook').item.json.body.info).id;\ntext_info['full_text'] = info;\noutput_info['text'] = JSON.stringify(text_info);\noutput_info['msg_info'] = info;\noutput_info['user_id'] = user_id;\nreturn output_info;"
},
"id": "6333557d-9ca3-4555-9a65-1361c41809b3",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1380,
480
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n",
"options": {}
},
"id": "ef6698e3-3965-4ce6-b49a-793488950293",
"name": "update_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1380,
760
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "5b7401bc-8c3c-426f-aada-69738c731e1a",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
980,
640
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }} and news_type = 1;\n",
"options": {}
},
"id": "7526411c-9bbb-485a-a7dd-680a867e61c8",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
740,
640
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL record_craw_zh_counts({{JSON.stringify(($json.body.info.parseJson().removeField(\"full_text\").toJsonString()))}},{{JSON.stringify(JSON.stringify($json.body.schedule_id)) }});",
"options": {}
},
"id": "7641b5d5-ff9f-45bf-a908-5d74feda160a",
"name": "record_zh_info",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
740,
380
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source_keyword({{ (JSON.stringify($json.data))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "eee34fe1-025b-458b-ad86-789dd8225027",
"name": "insert_news_source",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1860,
480
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\n// console.log(result_data);\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nfull_text_origial = info_data_list.full_text.replace(/https:\\/\\/[^\\s]+/g, '');\n// full_text_origial = result_data[0].json.msg_info;\ninfo_data_list['full_text'] = full_text_origial\ninfo_data_list['full_text_ch'] = full_text_origial;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\nlocation_data = info_data_list.location;\nif(isEmptyString(location_data)){\n location_data_arr = \"\";\n}else{\n location_data_arr = JSON.parse(info_data_list.location);\n}\nfull_text_new = info_data_list.full_text.replace(/'/g, \"\").replace(/\"/g, \"\");\nfull_text_ch_new = info_data_list.full_text_ch.replace(/'/g, \"\").replace(/\"/g, \"\");\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+full_text_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+full_text_ch_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.screen_name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.profile_image_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.favourite_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.retweet_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.view_count+\"'\";\nnews_item_data += ',';\nif(isEmptyString(location_data_arr)){\n news_item_data += \"''\";\n news_item_data += ',';\n news_item_data += \"''\";\n news_item_data += ',';\n}else{\n news_item_data += \"'\"+location_data_arr[0]+\"'\";\n news_item_data += ',';\n news_item_data += \"'\"+location_data_arr[1]+\"'\";\n news_item_data += ',';\n}\nnews_item_data += \"'zh_cn'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.created_at+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'twitter_search'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.news_type+\"'\";\nnews_item_data += ')';\n// city_code = info_data_list.city_code;\n// item_data = \"(\";\n// item_data += \"'\"+city_code+\"'\";\n// item_data += ',';\n// item_data += '@last_insert_id';\n// item_data += '),';\n// output_news_data_str += item_data;\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\n// output_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all_data_temp['label_data'] = [];\noutput_all_data_temp['artificial_label_data'] = [];\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "adfab857-87bd-491f-bbdd-fbe648698228",
"name": "get_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1620,
480
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/keyword",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "143f76d0-318e-4950-b32e-800a586108dc",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
480,
640
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_info": {
"main": [
[
{
"node": "get_news_sql",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
],
[
{
"node": "update_city_news",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"get_news_sql": {
"main": [
[
{
"node": "insert_news_source",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
},
{
"node": "record_zh_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "18a841df-ec80-41f8-ad68-358afd2727ac",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-05-06T06:19:14.658Z",
"updatedAt": "2025-05-06T06:19:14.658Z",
"role": "workflow:owner",
"workflowId": "NVlFW3egbrGCTDLb",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-02T09:24:15.067Z",
"updatedAt": "2025-04-09T09:34:43.000Z",
"id": "TxcqhO3oQgLzu2LF",
"name": "tw_search_no_fy",
"active": true,
"nodes": [
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = JSON.parse($('Webhook').item.json.body.info).full_text.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ').replaceAll(\"\\\"\", '” ');\n// console.log(info);\nuser_id = JSON.parse($('Webhook').item.json.body.info).id;\ntext_info['full_text'] = info;\noutput_info['text'] = JSON.stringify(text_info);\noutput_info['msg_info'] = info;\noutput_info['user_id'] = user_id;\nreturn output_info;"
},
"id": "ef5d2483-7f69-4ed8-9eb4-22bd2129cbcc",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-380,
1020
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source_no_fy({{ (JSON.stringify($json.data))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "e97de582-6a3c-4871-8357-4764e0d49f44",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
300,
1020
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\n// console.log(result_data);\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nfull_text_origial = info_data_list.full_text.replace(/https:\\/\\/[^\\s]+/g, '');\n// full_text_origial = result_data[0].json.msg_info;\ninfo_data_list['full_text'] = full_text_origial\ninfo_data_list['full_text_ch'] = full_text_origial;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\nfull_text_new = info_data_list.full_text.replace(/'/g, \"\").replace(/\"/g, \"\");\nfull_text_ch_new = info_data_list.full_text_ch.replace(/'/g, \"\").replace(/\"/g, \"\");\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+full_text_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+full_text_ch_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.screen_name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.profile_image_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.favourite_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.retweet_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.view_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'zh_cn'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.created_at+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'twitter_search'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'1'\";\nnews_item_data += ')';\ncity_code = info_data_list.city_code;\nitem_data = \"(\";\nitem_data += \"'\"+city_code+\"'\";\nitem_data += ',';\nitem_data += '@last_insert_id';\nitem_data += '),';\noutput_news_data_str += item_data;\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all_data_temp['label_data'] = [];\noutput_all_data_temp['artificial_label_data'] = [];\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "b88a5eb3-682e-41c3-a0a1-5707602fe4df",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-40,
1020
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n",
"options": {}
},
"id": "c6d87581-cc17-4e51-8988-ec9834b358d1",
"name": "update_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-380,
1560
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "eb2519df-1655-4f93-a217-90100ade157f",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-780,
1280
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "2e1ae342-37d7-483f-ab96-1b0bf1555532",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-1020,
1280
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\noutput_news_data_str = '';\noutput_all_data = {};\noutput_all = [];\noutput_city_code_list = [];\ncity_code = info_data_list.city_code;\noutput_city_code_list.push(city_code);\noutput_all_data['city_code'] = output_city_code_list;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all.push(output_all_data);\nconsole.log(output_all);\nreturn output_all;"
},
"id": "529aff1a-17a4-41a0-bfbe-6b9291f2fc31",
"name": "get_city_code_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-380,
1300
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_city({{ JSON.stringify(JSON.stringify($json.city_code))}},{{ JSON.stringify(JSON.stringify($json.news_id)) }});",
"options": {}
},
"id": "823030a0-715c-4da8-a036-a57b97d39d7c",
"name": "insert_city_data",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-40,
1300
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL record_craw_zh_counts({{JSON.stringify(($json.body.info.parseJson().removeField(\"full_text\").toJsonString()))}},{{JSON.stringify(JSON.stringify($json.body.schedule_id)) }});",
"options": {}
},
"id": "0daa36c2-30fc-4ca7-9c3c-f7d02074b9be",
"name": "record_zh_info",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-1020,
1020
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/nofy",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "6bf7acc2-de8e-45d7-9a80-d637d90ef554",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-1280,
1280
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_info": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
],
[
{
"node": "update_city_news",
"type": "main",
"index": 0
},
{
"node": "get_city_code_info",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"get_city_code_info": {
"main": [
[
{
"node": "insert_city_data",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
},
{
"node": "record_zh_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "76f906fe-07bc-4a0f-8c66-6bc86ed50235",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-02T09:24:15.077Z",
"updatedAt": "2025-04-02T09:24:15.077Z",
"role": "workflow:owner",
"workflowId": "TxcqhO3oQgLzu2LF",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T10:34:59.655Z",
"updatedAt": "2025-04-07T07:04:14.000Z",
"id": "t9XHS24HKkdH7F7s",
"name": "twitter_search",
"active": true,
"nodes": [
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = JSON.parse($('Webhook').item.json.body.info).full_text.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ').replaceAll(\"\\\"\", '” ');\nconsole.log(info);\nuser_id = JSON.parse($('Webhook').item.json.body.info).id;\ntext_info['full_text'] = info;\noutput_info['text'] = JSON.stringify(text_info);\noutput_info['msg_info'] = info;\noutput_info['user_id'] = user_id;\nreturn output_info;"
},
"id": "e829c01b-3921-4eed-98e5-b1dc9436ff03",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-140,
480
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source({{ (JSON.stringify($json.data))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "e01f5445-6df0-4077-8a9e-7ae992795074",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1000,
940
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('label_data' in item_data){\n content_all['label'] = item_data['label_data'];\n }else if('artificial_label_data' in item_data){\n content_all['artificial_label'] = item_data['artificial_label_data'];\n }\n};\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nlabel_data_list = content_all.label;\nartificial_label_data_list = content_all.artificial_label;\nif(artificial_label_data_list.length>0){\n artificial_label_data_list[0]['city_code'] = info_data_list.city_code;;\n}\ninfo_data_list['full_text'] = info_data_list.full_text.replace(/https:\\/\\/[^\\s]+/g, '');\ntranster_answer_data = $('get_transter_answer').all()[0].json.answer.full_text;\ninfo_data_list['full_text_ch'] = transter_answer_data;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\noutput_news_label_data_str = \"\";\nfull_text_new = info_data_list.full_text.replace(/'/g, \"\").replace(/\"/g, \"\");\nfull_text_ch_new = info_data_list.full_text_ch.replace(/'/g, \"\").replace(/\"/g, \"\");\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+full_text_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+full_text_ch_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.screen_name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.profile_image_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.favourite_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.retweet_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.view_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'zh_cn'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.created_at+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'twitter_search'\";\nnews_item_data += ',';\nnews_item_data += \"'1'\";\nnews_item_data += ')';\ncity_code = info_data_list.city_code;\nitem_data = \"(\";\nitem_data += \"'\"+city_code+\"'\";\nitem_data += ',';\nitem_data += '@last_insert_id';\nitem_data += '),';\noutput_news_data_str += item_data;\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all_data_temp['label_data'] = label_data_list;\noutput_all_data_temp['artificial_label_data'] = artificial_label_data_list;\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "4423a7a8-0a70-4995-b5a5-a1e51e88ebbe",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
740,
940
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n",
"options": {}
},
"id": "6f2c43b2-39ea-4d24-b04f-6e7ba8e295a0",
"name": "update_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
480,
1480
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "e4a2dadb-65d8-45f6-b473-ac28ab739de9",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-420,
980
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "70250832-140c-466f-9c00-64f63c9accde",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-660,
980
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KRXKS2lXohYjnIKmuYxSncem\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "f5e0c3a1-71dc-4ea3-b103-3f2d10471c93",
"name": "translate_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
40,
480
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\nfunction isEmpty(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value) {\n return true;\n }\n return false;\n};\nlabel_data_list = [];\nartificial_label_data_list = [];\nlabel_data_arr = $input.all();\nlabel_result_list = [];\nartificial_label_result_list = [];\nfor(var label_index=0;label_index<label_data_arr.length;label_index++){\n label_data_temp = label_data_arr[label_index];\n workflow_id = label_data_temp.json.data.workflow_id;\n label_data_output_list = label_data_temp.json.data.outputs;\n if(workflow_id == '767511d7-ccf6-42c1-a42e-b2c14959c147'){\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n for (let i = 0; i < label_result.length; i++) {\n label_result_list.push(label_result[i]);\n }\n }\n }else{\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n let label_index_temp = 0;\n for (let i = 0; i < label_result.length&&label_index_temp<1; i++) {\n artificial_label_result_list.push(label_result[i]);\n label_index_temp += 1;\n }\n } \n }\n};\n// console.log(label_result_list);\nfor (let i = 0; i < label_result_list.length; i++) {\n label_code_score = {};\n label_code = label_result_list[i].code;\n label_score = label_result_list[i].score;\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['score'] = label_score;\n label_data_list.push(label_code_score);\n }\n};\nfor (let i = 0; i < artificial_label_result_list.length; i++) {\n label_code_score = {};\n label_code = artificial_label_result_list[i].code;\n label_name = artificial_label_result_list[i].name;\n label_score = artificial_label_result_list[i].score;\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['name'] = label_name;\n label_code_score['score'] = label_score;\n artificial_label_data_list.push(label_code_score);\n }\n};\nlabel_data_list_2 = [];\nlabel_data_json = {};\nartificial_label_data_json = {};\nlabel_data_json[\"label_data\"] = label_data_list;\nartificial_label_data_json[\"artificial_label_data\"] = artificial_label_data_list;\n// console.log(label_data_json);\nlabel_data_list_2.push(label_data_json);\nlabel_data_list_2.push(artificial_label_data_json);\nreturn label_data_list_2;"
},
"id": "00345540-52ea-4185-baa8-9de02ecf0aaf",
"name": "get_label_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1000,
600
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\nanswer =$input.all()[0].json.answer;\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nreturn answer_data;"
},
"id": "2ce1807e-dd97-45af-91d7-15c5310f4a7f",
"name": "get_transter_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
220,
480
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KNq0O8kENP4ITqSmqHQ0IzAt\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$('get_info').item.json.msg_info.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "779e5be9-c03f-41ab-bb8b-787746c9d15c",
"name": "natural_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
480,
600
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-HCbsiZmUCzP8Vdqb2meKXQSb\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$json.answer.full_text.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "39348acd-530f-47cc-acae-cab6a1793038",
"name": "artificial_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
480,
400
]
},
{
"parameters": {},
"id": "b614c512-d925-4f6b-befb-6b3959c01377",
"name": "merge_label",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
700,
500
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\noutput_news_data_str = '';\noutput_all_data = {};\noutput_all = [];\noutput_city_code_list = [];\ncity_code = info_data_list.city_code;\noutput_city_code_list.push(city_code);\noutput_all_data['city_code'] = output_city_code_list;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all.push(output_all_data);\nconsole.log(output_all);\nreturn output_all;"
},
"id": "6cb86ad1-2b0e-4b4f-9d0a-09851419fc72",
"name": "get_city_code_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
480,
1200
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_city({{ JSON.stringify(JSON.stringify($json.city_code))}},{{ JSON.stringify(JSON.stringify($json.news_id)) }});",
"options": {}
},
"id": "03c554a7-ffb4-4f54-b95b-3ed071e79645",
"name": "insert_city_data",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
740,
1200
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {},
"id": "764927cc-b964-4fd8-bf0b-0ac66f131972",
"name": "get_answer_location",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
480,
940
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "1ed229b2-7a41-4ac8-baf9-6f27b8667350",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-920,
980
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL record_craw_zh_counts({{JSON.stringify(($json.body.info.parseJson().removeField(\"full_text\").toJsonString()))}},{{JSON.stringify(JSON.stringify($json.body.schedule_id)) }});",
"options": {}
},
"id": "3c92c7f7-c7f4-4258-a5aa-536fd69eaf15",
"name": "record_zh_info",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-660,
720
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
}
],
"connections": {
"get_info": {
"main": [
[
{
"node": "translate_dify",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
},
{
"node": "get_answer_location",
"type": "main",
"index": 1
}
],
[
{
"node": "update_city_news",
"type": "main",
"index": 0
},
{
"node": "get_city_code_info",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"translate_dify": {
"main": [
[
{
"node": "get_transter_answer",
"type": "main",
"index": 0
}
]
]
},
"get_label_answer": {
"main": [
[
{
"node": "get_answer_location",
"type": "main",
"index": 0
}
]
]
},
"get_transter_answer": {
"main": [
[
{
"node": "artificial_label_dify",
"type": "main",
"index": 0
},
{
"node": "natural_label_dify",
"type": "main",
"index": 0
}
]
]
},
"natural_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 1
}
]
]
},
"artificial_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 0
}
]
]
},
"merge_label": {
"main": [
[
{
"node": "get_label_answer",
"type": "main",
"index": 0
}
]
]
},
"get_city_code_info": {
"main": [
[
{
"node": "insert_city_data",
"type": "main",
"index": 0
}
]
]
},
"get_answer_location": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
},
{
"node": "record_zh_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "154c2c09-0457-4642-82a6-d1a60126ff23",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T10:34:59.666Z",
"updatedAt": "2025-02-13T10:34:59.666Z",
"role": "workflow:owner",
"workflowId": "t9XHS24HKkdH7F7s",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-02T02:40:53.422Z",
"updatedAt": "2025-04-05T01:38:20.000Z",
"id": "2noMs2OyiqykKc0j",
"name": "twitter_search_no_fy_test",
"active": false,
"nodes": [
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = JSON.parse($('Webhook').item.json.body.info).full_text.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ').replaceAll(\"\\\"\", '” ');\n// console.log(info);\nuser_id = JSON.parse($('Webhook').item.json.body.info).id;\ntext_info['full_text'] = info;\noutput_info['text'] = JSON.stringify(text_info);\noutput_info['msg_info'] = info;\noutput_info['user_id'] = user_id;\nreturn output_info;"
},
"id": "c0872d0d-ae54-4aeb-ab6d-12fa6837a1d0",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-20,
660
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source_no_fy({{ (JSON.stringify($json.data))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "d1dbe6f3-c308-4f70-813a-9b8581b51ae9",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
660,
660
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\n// console.log(result_data);\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nfull_text_origial = info_data_list.full_text.replace(/https:\\/\\/[^\\s]+/g, '');\n// full_text_origial = result_data[0].json.msg_info;\ninfo_data_list['full_text'] = full_text_origial\ninfo_data_list['full_text_ch'] = full_text_origial;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\nfull_text_new = info_data_list.full_text.replace(/'/g, \"\").replace(/\"/g, \"\").replace(/[-]/g, \" \");\nfull_text_ch_new = info_data_list.full_text_ch.replace(/'/g, \"\").replace(/\"/g, \"\").replace(/[-]/g, \" \");\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+full_text_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+full_text_ch_new+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.screen_name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.profile_image_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.favourite_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.retweet_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.view_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'zh_cn'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.created_at+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'twitter_search'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'1'\";\nnews_item_data += ')';\ncity_code = info_data_list.city_code;\nitem_data = \"(\";\nitem_data += \"'\"+city_code+\"'\";\nitem_data += ',';\nitem_data += '@last_insert_id';\nitem_data += '),';\noutput_news_data_str += item_data;\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all_data_temp['label_data'] = [];\noutput_all_data_temp['artificial_label_data'] = [];\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "beb92f14-b10d-41c7-b492-26351bd8166b",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
320,
660
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n",
"options": {}
},
"id": "dc816085-9624-48c7-bef6-717f800012e6",
"name": "update_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-20,
1200
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "935d5d41-cf0a-4e66-b1ae-900f9f3a2b45",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-420,
920
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "3e97d204-d1dc-4d68-940e-b55c1e6af7d8",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-660,
920
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KRXKS2lXohYjnIKmuYxSncem\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "aefac2f8-6337-453e-a028-ee13669cb2d4",
"name": "translate_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
220,
160
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\nfunction isEmpty(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value) {\n return true;\n }\n return false;\n};\nlabel_data_list = [];\nartificial_label_data_list = [];\nlabel_data_arr = $input.all();\nlabel_result_list = [];\nartificial_label_result_list = [];\nfor(var label_index=0;label_index<label_data_arr.length;label_index++){\n label_data_temp = label_data_arr[label_index];\n workflow_id = label_data_temp.json.data.workflow_id;\n label_data_output_list = label_data_temp.json.data.outputs;\n if(workflow_id == '767511d7-ccf6-42c1-a42e-b2c14959c147'){\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n for (let i = 0; i < label_result.length; i++) {\n label_result_list.push(label_result[i]);\n }\n }\n }else{\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n let label_index_temp = 0;\n for (let i = 0; i < label_result.length&&label_index_temp<1; i++) {\n artificial_label_result_list.push(label_result[i]);\n label_index_temp += 1;\n }\n } \n }\n};\n// console.log(label_result_list);\nfor (let i = 0; i < label_result_list.length; i++) {\n label_code_score = {};\n label_code = label_result_list[i].code;\n label_score = label_result_list[i].score;\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['score'] = label_score;\n label_data_list.push(label_code_score);\n }\n};\nfor (let i = 0; i < artificial_label_result_list.length; i++) {\n label_code_score = {};\n label_code = artificial_label_result_list[i].code;\n label_name = artificial_label_result_list[i].name;\n label_score = artificial_label_result_list[i].score;\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['name'] = label_name;\n label_code_score['score'] = label_score;\n artificial_label_data_list.push(label_code_score);\n }\n};\nlabel_data_list_2 = [];\nlabel_data_json = {};\nartificial_label_data_json = {};\nlabel_data_json[\"label_data\"] = label_data_list;\nartificial_label_data_json[\"artificial_label_data\"] = artificial_label_data_list;\n// console.log(label_data_json);\nlabel_data_list_2.push(label_data_json);\nlabel_data_list_2.push(artificial_label_data_json);\nreturn label_data_list_2;"
},
"id": "723b5eea-2cdd-49e5-8a32-11a2e72f39c3",
"name": "get_label_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1320,
140
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\nanswer =$input.all()[0].json.answer;\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nreturn answer_data;"
},
"id": "0838f5ca-0eeb-4d84-a23b-d8fb9fc7f004",
"name": "get_transter_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
480,
160
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-SRHXAMF0iYxuCJD5cnHYgtJZ\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$('get_info').item.json.msg_info.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "256a2a75-3847-4f76-9555-40071ccce049",
"name": "natural_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
760,
280
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-HCbsiZmUCzP8Vdqb2meKXQSb\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$json.answer.full_text.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "497c6388-9d24-4d4d-ab11-1e47342da941",
"name": "artificial_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
760,
20
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\noutput_news_data_str = '';\noutput_all_data = {};\noutput_all = [];\noutput_city_code_list = [];\ncity_code = info_data_list.city_code;\noutput_city_code_list.push(city_code);\noutput_all_data['city_code'] = output_city_code_list;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all.push(output_all_data);\nconsole.log(output_all);\nreturn output_all;"
},
"id": "9a02ea3a-8a1a-475e-b7fd-bca2433bc37c",
"name": "get_city_code_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-20,
940
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_city({{ JSON.stringify(JSON.stringify($json.city_code))}},{{ JSON.stringify(JSON.stringify($json.news_id)) }});",
"options": {}
},
"id": "f0424694-29a7-4a4f-905e-c7e03c02df67",
"name": "insert_city_data",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
320,
940
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL record_craw_zh_counts({{JSON.stringify(($json.body.info.parseJson().removeField(\"full_text\").toJsonString()))}},{{JSON.stringify(JSON.stringify($json.body.schedule_id)) }});",
"options": {}
},
"id": "8b16b866-10d6-4e43-b8d0-0cdeeb54be12",
"name": "record_zh_info",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-660,
660
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {},
"id": "c92f6728-f517-4ece-8419-114e5b192b7d",
"name": "get_answer_location",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
1280,
520
]
},
{
"parameters": {},
"id": "8227063d-9650-4f2f-b7c0-e19b6f9d16df",
"name": "merge_label",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
1040,
140
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/search/nofy/test",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "59ebbce7-30f2-401b-b7d7-ed86519b7729",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-920,
920
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_info": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
],
[
{
"node": "update_city_news",
"type": "main",
"index": 0
},
{
"node": "get_city_code_info",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"translate_dify": {
"main": [
[
{
"node": "get_transter_answer",
"type": "main",
"index": 0
}
]
]
},
"get_label_answer": {
"main": [
[
{
"node": "get_answer_location",
"type": "main",
"index": 0
}
]
]
},
"get_transter_answer": {
"main": [
[
{
"node": "artificial_label_dify",
"type": "main",
"index": 0
},
{
"node": "natural_label_dify",
"type": "main",
"index": 0
}
]
]
},
"natural_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 1
}
]
]
},
"artificial_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 0
}
]
]
},
"get_city_code_info": {
"main": [
[
{
"node": "insert_city_data",
"type": "main",
"index": 0
}
]
]
},
"merge_label": {
"main": [
[
{
"node": "get_label_answer",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
},
{
"node": "record_zh_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "e65ea9da-d8d0-45a7-9cd0-62ad1c8a6b29",
"triggerCount": 0,
"shared": [
{
"createdAt": "2025-04-02T02:40:53.437Z",
"updatedAt": "2025-04-02T02:40:53.437Z",
"role": "workflow:owner",
"workflowId": "2noMs2OyiqykKc0j",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:36:08.382Z",
"updatedAt": "2025-02-13T05:36:19.000Z",
"id": "bk8jytHJxIiEJZJN",
"name": "update-twitter",
"active": true,
"nodes": [
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "8b39a311-a36b-48bb-9eac-062957839b7d",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-400,
900
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "d6aaa8cc-c453-416f-86af-23e508e9a85f",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-640,
900
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/update",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "1e91e2e1-ffbb-40d7-b2f8-e42c2cb09b68",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-900,
900
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "1fHtEpWRIg2mFYBe",
"name": "Header Auth account"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n",
"options": {}
},
"id": "90f5d164-5bad-4f66-a280-9b033773d309",
"name": "update_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-20,
900
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
}
],
"connections": {
"insert_or_update": {
"main": [
[
{
"node": "update_news",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": null,
"pinData": null,
"versionId": "f68481c0-5950-4b12-9259-1c5e618ac825",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:36:08.395Z",
"updatedAt": "2025-02-13T05:36:08.395Z",
"role": "workflow:owner",
"workflowId": "bk8jytHJxIiEJZJN",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-17T09:44:19.773Z",
"updatedAt": "2025-07-14T02:31:54.000Z",
"id": "F1JOTttlqjI2J3A1",
"name": "warn_report_news",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from report_news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).news_uid) }};\n",
"options": {}
},
"id": "520f8bba-4b61-4e2e-8cf9-5ab6d63a9671",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
200,
660
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "d0e324a5-78e0-430a-9569-8d83201c3f17",
"name": "is_save",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
420,
660
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\noutput_all = [];\noutput_all_data = {};\noutput_news_url_data_str = \"\";\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+info_data_list.title+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.content+\"'\";\nnews_item_data += ',';\nif(isEmptyString(info_data_list.author)){\n news_item_data += null;\n}else{\n news_item_data += \"'\"+info_data_list.author+\"'\";\n}\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.source_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.level_1+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.level_2+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.status+\"'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.publish_time+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\n// news_item_data += \"'\"+info_data_list.source_content+\"'\";\n// news_item_data += ',';\nnews_item_data += \"'\"+info_data_list.news_web+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.news_uid+\"'\";\nnews_item_data += ',';\nif(isEmptyString(info_data_list.schedule_id)){\n news_item_data += null;\n}else{\n news_item_data += \"'\"+info_data_list.schedule_id+\"'\";\n}\nnews_item_data += ')';\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '4';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '4';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\n\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "9be91cd6-49cd-43ea-bc28-1ef69276aea2",
"name": "get_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
720,
500
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '0';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "fc967c1b-1027-4b32-8ba5-dbbda36836db",
"name": "return_result",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
720,
760
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "7a98c320-1185-4572-8de4-850445f89af2",
"name": "return_save_flag",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1420,
380
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ JSON.parse($json.data).urls_data.toString() }}",
"rightValue": "=('','','','')",
"operator": {
"type": "string",
"operation": "notEquals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "159cc7c9-db5a-4ece-b901-8b055203065f",
"name": "is_url",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
940,
500
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO report_news_source (title,content,author,source_url,type_1,type_2,status,publish_time,news_web,news_uid,schedule_id) VALUES {{ JSON.parse($json.data).news_data }};\n\n-- SET @last_insert_id = LAST_INSERT_ID();\n-- INSERT INTO news_url (url,thumbnail_url,type,status,news_id) VALUES {{ JSON.parse($json.data).urls_data }};\n\nCOMMIT;",
"options": {}
},
"id": "ff09d9a6-5be1-4cfe-bf58-9f99205381db",
"name": "save_news_url",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1200,
380
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO report_news_source (title,content,author,source_url,type_1,type_2,status,publish_time,news_web,news_uid,schedule_id) VALUES {{ JSON.parse($json.data).news_data }};\n\nCOMMIT;",
"options": {}
},
"id": "464be59d-6e5f-4e28-b5b4-7e3c3e0f85fc",
"name": "save_news_no_url",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1200,
620
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "4b86c505-4226-4bff-8508-b2bde4badd8e",
"name": "return_save_flag_2",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1420,
620
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "warn/wjbwlb/save",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "489a6a4a-295d-4d27-afd9-b971bfd4e820",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
0,
660
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"is_exists_news": {
"main": [
[
{
"node": "is_save",
"type": "main",
"index": 0
}
]
]
},
"is_save": {
"main": [
[
{
"node": "get_news_sql",
"type": "main",
"index": 0
}
],
[
{
"node": "return_result",
"type": "main",
"index": 0
}
]
]
},
"get_news_sql": {
"main": [
[
{
"node": "is_url",
"type": "main",
"index": 0
}
]
]
},
"is_url": {
"main": [
[
{
"node": "save_news_url",
"type": "main",
"index": 0
}
],
[
{
"node": "save_news_no_url",
"type": "main",
"index": 0
}
]
]
},
"save_news_url": {
"main": [
[
{
"node": "return_save_flag",
"type": "main",
"index": 0
}
]
]
},
"save_news_no_url": {
"main": [
[
{
"node": "return_save_flag_2",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "103f8ecc-131e-436b-ae1d-54b2479524b7",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-17T09:44:19.785Z",
"updatedAt": "2025-04-17T09:44:19.785Z",
"role": "workflow:owner",
"workflowId": "F1JOTttlqjI2J3A1",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:21:02.506Z",
"updatedAt": "2025-07-10T04:03:47.000Z",
"id": "bQ05yfERnnrZ8DMJ",
"name": "webhook_crimemap",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as source_num from crime_mapping cm where cm.source_id ={{JSON.stringify(JSON.parse($json.body.info).Incident)}};\n\n",
"options": {}
},
"id": "195caf2a-b22a-4c30-83d1-a3cee02793c6",
"name": "is_safe_exist",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-560,
340
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\ninfo_data_list = JSON.parse($('Webhook').item.json.body.info);\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\nnews_item_data = \"\";\nzone_data = {};\nzone_data['lat'] = info_data_list.lat;\nzone_data['lon'] = info_data_list.lng;\nzone_data_str = JSON.stringify(zone_data);\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+zone_data_str+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Description+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Type_url+'\"';\n// news_item_data += ',';\n// news_item_data += '\"0\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.lang_code+'\"';\nnews_item_data += ',';\nif(!isEmptyString(info_data_list.Date)){\n news_item_data += 'STR_TO_DATE(\"'+info_data_list.Date+'\",\"%Y-%m-%d %H:%i:%s\")';\n news_item_data += ',';\n}else{\n // news_item_data += 'NOW()';\n news_item_data += 'STR_TO_DATE(NOW(),\"%Y-%m-%d %H:%i:%s\")';\n news_item_data += ',';\n};\nnews_item_data += '\"'+info_data_list.Type+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Location+'\"';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.addition+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Incident+'\"';\nnews_item_data += ')';\ncity_code_list = info_data_list.city_code.split(\",\");\nfor (let i = 0; i < city_code_list.length; i++) {\n city_code = city_code_list[i];\n item_data = \"(\";\n item_data += '\"'+city_code+'\"';\n item_data += ',';\n item_data += '@last_insert_id';\n item_data += '),';\n output_news_data_str += item_data;\n};\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['safe_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "426acf11-f41c-4872-8e63-19a066912c98",
"name": "get_safe_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-140,
220
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO crime_mapping (zone,content,icon,lang_code,event_time,event,address,addition,source_id) VALUES {{ $json.safe_data }};\n\nSET @last_insert_id = LAST_INSERT_ID();\n\nINSERT INTO city_guide (city_code, source_id)\nVALUES {{ $json.city_data }};\n\nCOMMIT;",
"options": {
"detailedOutput": true
}
},
"id": "186b2435-54c0-43d5-81a9-9fe4782c508c",
"name": "insert_safe",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
80,
220
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "37fd1a36-8c69-4438-8fdc-6181956dfae3",
"leftValue": "={{ $json.source_num.toString()}}",
"rightValue": "0",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
},
{
"id": "e8a93e70-faee-4ad7-865b-c76ee1fc6270",
"leftValue": "={{ JSON.parse($('Webhook').item.json.body.info).city_code }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "notEmpty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "27ab6f03-fce6-4cab-8fcb-05411292caba",
"name": "If_1",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-380,
340
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "37fd1a36-8c69-4438-8fdc-6181956dfae3",
"leftValue": "={{ $json.source_num.toString()}}",
"rightValue": "0",
"operator": {
"type": "string",
"operation": "equals",
"name": "filter.operator.equals"
}
},
{
"id": "e8a93e70-faee-4ad7-865b-c76ee1fc6270",
"leftValue": "={{ JSON.parse($('Webhook').item.json.body.info).city_code }}",
"rightValue": "",
"operator": {
"type": "string",
"operation": "empty",
"singleValue": true
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "6d7ffe8d-a49c-4924-acab-4c4b95564f7a",
"name": "If_2",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-140,
480
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\ninfo_data_list = JSON.parse($('Webhook').item.json.body.info);\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\nnews_item_data = \"\";\nzone_data = {};\nzone_data['lat'] = info_data_list.lat;\nzone_data['lon'] = info_data_list.lng;\nzone_data_str = JSON.stringify(zone_data);\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+zone_data_str+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Description+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Type_url+'\"';\n// news_item_data += ',';\n// news_item_data += '\"0\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.lang_code+'\"';\nnews_item_data += ',';\nif(!isEmptyString(info_data_list.Date)){\n news_item_data += 'STR_TO_DATE(\"'+info_data_list.Date+'\",\"%Y-%m-%d %H:%i:%s\")';\n news_item_data += ',';\n}else{\n // news_item_data += 'NOW()';\n news_item_data += 'STR_TO_DATE(NOW(),\"%Y-%m-%d %H:%i:%s\")';\n news_item_data += ',';\n};\nnews_item_data += '\"'+info_data_list.Type+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Location+'\"';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.addition+\"'\";\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.Incident+'\"';\nnews_item_data += ')';\n// city_code = info_data_list.city_code;\n// item_data = \"(\";\n// item_data += '\"'+city_code+'\"';\n// item_data += ',';\n// item_data += '@last_insert_id';\n// item_data += ')';\n// output_news_data_str += item_data;\n// output_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length);\noutput_all_data['safe_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "c9e9c09e-cff1-47d1-aaa1-f88a984f3279",
"name": "get_safe_sql_no_city",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
80,
460
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO crime_mapping (zone,content,icon,lang_code,event_time,event,address,addition,source_id) VALUES {{ $json.safe_data }};\n\n-- SET @last_insert_id = LAST_INSERT_ID();\n\n-- INSERT INTO city_guide (city_code, source_id)\n-- VALUES {{ $json.city_data }};\n\nCOMMIT;",
"options": {
"detailedOutput": true
}
},
"id": "a03b8434-2792-4fda-a47b-ce621da16fac",
"name": "insert_safe_no_city",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
260,
460
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data_list = $input.all();\ninsert_id = '';\nfor(var i=0;i<result_data_list.length;i++){\n result_data = result_data_list[i].json;\n sql_val = result_data.sql;\n if(sql_val.indexOf(\"crime_mapping\")>0){\n data_temp = result_data.data;\n if(!isNullOrEmpty(data_temp)){\n insert_id = data_temp.insertId;\n break;\n }\n }\n}\nfunction isNullOrEmpty(obj) {\n return obj === null || obj === undefined || (typeof obj === 'object' && !Array.isArray(obj) && Object.keys(obj).length === 0);\n}\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all_data['insert_id'] = insert_id;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "8833b540-5ec2-44aa-b59b-04f2ececd377",
"name": "return_save_flag",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
260,
220
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data_list = $input.all();\ninsert_id = '';\nfor(var i=0;i<result_data_list.length;i++){\n result_data = result_data_list[i].json;\n sql_val = result_data.sql;\n if(sql_val.indexOf(\"crime_mapping\")>0){\n data_temp = result_data.data;\n if(!isNullOrEmpty(data_temp)){\n insert_id = data_temp.insertId;\n break;\n }\n }\n}\nfunction isNullOrEmpty(obj) {\n return obj === null || obj === undefined || (typeof obj === 'object' && !Array.isArray(obj) && Object.keys(obj).length === 0);\n}\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all_data['insert_id'] = insert_id;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "2435bf3c-49dd-4a98-b046-065bfcb5859a",
"name": "return_save_flag1",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
460,
460
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "crime/save",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "50ff17b5-bf4a-4352-803c-d726dac3248e",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-740,
340
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '0';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "44b1fb28-351c-4f7c-b398-a7336396c556",
"name": "return_save_flag2",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
80,
660
]
}
],
"connections": {
"is_safe_exist": {
"main": [
[
{
"node": "If_1",
"type": "main",
"index": 0
}
]
]
},
"get_safe_sql": {
"main": [
[
{
"node": "insert_safe",
"type": "main",
"index": 0
}
]
]
},
"If_1": {
"main": [
[
{
"node": "get_safe_sql",
"type": "main",
"index": 0
}
],
[
{
"node": "If_2",
"type": "main",
"index": 0
}
]
]
},
"If_2": {
"main": [
[
{
"node": "get_safe_sql_no_city",
"type": "main",
"index": 0
}
],
[
{
"node": "return_save_flag2",
"type": "main",
"index": 0
}
]
]
},
"get_safe_sql_no_city": {
"main": [
[
{
"node": "insert_safe_no_city",
"type": "main",
"index": 0
}
]
]
},
"insert_safe": {
"main": [
[
{
"node": "return_save_flag",
"type": "main",
"index": 0
}
]
]
},
"insert_safe_no_city": {
"main": [
[
{
"node": "return_save_flag1",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_safe_exist",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "b724dcee-1893-420d-9713-e64f7dd16372",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:21:02.515Z",
"updatedAt": "2025-02-13T05:21:02.515Z",
"role": "workflow:owner",
"workflowId": "bQ05yfERnnrZ8DMJ",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2024-09-10T03:53:54.535Z",
"updatedAt": "2024-09-12T02:05:13.000Z",
"id": "s6zsznwVs6N4L2Hx",
"name": "webhook-guidesafe",
"active": false,
"nodes": [
{
"parameters": {
"table": {
"__rl": true,
"value": "city_safe_guide",
"mode": "list",
"cachedResultName": "city_safe_guide"
},
"options": {}
},
"id": "3897d8b1-7614-45ff-9aa5-a6cc289973ac",
"name": "MySQL",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
760,
220
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "MySQL account"
}
}
},
{
"parameters": {
"collection": "results_ls_fww",
"options": {},
"query": "{ \"schedule_id\": \"19\"}"
},
"id": "844aced7-ac0f-414e-a8d9-8f3973ebfb3a",
"name": "MongoDB",
"type": "n8n-nodes-base.mongoDb",
"typeVersion": 1.1,
"position": [
180,
320
],
"credentials": {
"mongoDb": {
"id": "D2GwCG2UAtnWPY8f",
"name": "MongoDB account"
}
}
},
{
"parameters": {
"language": "python",
"pythonCode": "# Loop over input items and add a new field called 'myNewField' to the JSON of each one\n\n import json,requests,time\n import pymysql,json\n from dbutils.pooled_db import PooledDB\n # 测试数据库\n mincached = 10 #连接池中空闲连接的初始数量\n maxcached = 20 #连接池中空闲连接的最大数量\n maxshared = 10 #共享连接的最大数量\n maxconnections = 200 #创建连接池的最大数量\n blocking = True #超过最大连接数量时候的表现,为True等待连接数量下降,为false直接报错处理\n maxusage = 100 #单个连接的最大重复使用次数\n maxsize = 10 #连接池最大连接数\n minsize = 1 #连接池最小连接数\n autocommit = True # 是否自动提交\n setsession = None #optional list of SQL commands that may serve to prepare the session, e.g. [\"set datestyle to ...\", \"set time zone ...\"]\n reset = True #how connections should be reset when returned to the pool(False or None to rollback transcations started with begin(),True to always issue a rollback for safety's sake)\n host = 'sldb-mysql.c368qw68qa1w.ap-east-1.rds.amazonaws.com' #数据库ip地址 sldb-mysql.c368qw68qa1w.ap-east-1.rds.amazonaws.com\n port = 3306 #数据库端口\n db = 'qa' #库名\n user = 'admin_sl_mysql' #用户名\n passwd = '2024mysql07sl' #密码\n charset = 'utf8mb4' #字符编码\n max_workers = 5 # 线程池最大线程数\n \n class MysqlClient(object):\n def __init__(self, mincached=mincached, maxcached=maxcached,\n maxshared=maxshared, maxconnections=maxconnections,\n blocking=blocking, maxusage=maxusage,\n setsession=setsession, reset=reset,\n host=host, port=port, db=db,\n user=user, passwd=passwd, charset=charset):\n \n self.__pool = PooledDB(pymysql,\n mincached, maxcached,\n maxshared, maxconnections, blocking,\n maxusage, setsession, reset,\n host=host, port=port, db=db,\n user=user, passwd=passwd,\n charset=charset,\n cursorclass=pymysql.cursors.DictCursor\n )\n \n \n def connect(self):\n _conn = self.__pool.connection()\n _cursor = _conn.cursor()\n return _conn,_cursor\n \n def select_table(self,sql, value_list):\n conn,cur = self.connect()\n try:\n cur.execute(sql, value_list)\n data = cur.fetchall()\n cur.close()\n conn.close()\n if data.__len__() > 0:\n return data\n else:\n return []\n except Exception as e:\n return []\n \n def dify_completion_messages(parse_text,out_data):\n post_url = 'http://47.99.137.247/v1/completion-messages'\n post_headers = {\n 'Authorization': \"Bearer app-ApuLSwN3ahfsL3CVAyKs3F0s\",\n 'Content-Type': 'application/json'\n }\n post_data = {\n \"inputs\": {\"query\": parse_text+\" 请将上述内容按照以下json格式输出,并需要符合json schema规范 \"+json.dumps(out_data)},\n \"response_mode\": \"blocking\",\n \"user\": \"mc\"\n }\n try:\n response = requests.post(post_url, headers=post_headers, data=json.dumps(post_data))\n # 检查响应状态码\n if response.status_code == 200:\n # 如果请求成功,处理响应数据\n response_data = json.loads(response.text)\n answer = response_data.get(\"answer\")\n start = answer.find(\"```\")\n indices = []\n while start != -1:\n indices.append(start)\n start = answer.find(\"```\", start + 1)\n print(indices)\n answer_data = json.loads(answer[indices[0] + 7:indices[1]])\n print(\"Response:\", response_data)\n return answer_data\n else:\n # 如果请求失败,打印错误信息\n print(f\"Request failed with status code {response.status_code}: {response.text}\")\n return None\n except Exception as e:\n print(f\"An error occurred: {e}\")\n return None\n \n mysql_client = MysqlClient()\n QUERY_CODE_NAME = \"select id,name_cn from code a where group_id = '10' and status = '0'\"\n # 根据计划id查询\n QUERY_LOCATION = \"select location from schedule a where a.id = '#1'\"\n code_data_list = mysql_client.select_table(QUERY_CODE_NAME, [])\n out_data = {}\n code_id_data = {}\n for code_data in code_data_list:\n id = code_data.get(\"id\")\n name_cn = code_data.get(\"name_cn\")\n out_data[name_cn] = 'xxx'\n code_id_data[name_cn] = id\n _output_all = []\n for item in _input.all():\n schedule_id = item.json.schedule_id\n location_data_list = mysql_client.select_table(QUERY_LOCATION.replace(\"#1\",schedule_id), [])\n location = None\n if location_data_list is not None and len(location_data_list) >0:\n location = json.loads(location_data_list[0].get(\"location\"))\n info = json.loads(item.json.content).get(\"实用信息\")\n dify_result_data = dify_completion_messages(info,out_data)\n if location is not None and len(location)>0 and dify_result_data is not None and len(dify_result_data)>0:\n for location_data in location:\n cityCode = location_data.get(\"cityCode\")\n for name_cn, data in dify_result_data.items():\n data_item = {}\n data_item['city_code'] = cityCode\n data_item['recommend'] = json.dumps(data)\n data_item['classification_id'] = code_id_data.get(\"name_cn\")\n _output_all.append(data_item) \n return _output_all\n "
},
"id": "93a88188-7975-4815-b9f9-38cd7013d531",
"name": "Code",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
540,
220
]
},
{
"parameters": {
"path": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"options": {}
},
"id": "c5626b71-d366-4b9b-9239-aacdecefdb5b",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-220,
220
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07"
},
{
"parameters": {
"operation": "select",
"table": {
"__rl": true,
"value": "code",
"mode": "list",
"cachedResultName": "code"
},
"options": {}
},
"id": "5979f414-7b71-4579-81b7-d64e8a95438d",
"name": "MySQL1",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
180,
0
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "MySQL account"
}
}
}
],
"connections": {
"MongoDB": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "MySQL",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "MongoDB",
"type": "main",
"index": 0
},
{
"node": "MySQL1",
"type": "main",
"index": 0
}
]
]
},
"MySQL1": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "d971e77d-442e-4852-8e08-c812d5e77bb4",
"triggerCount": 1,
"shared": [
{
"createdAt": "2024-09-10T03:53:54.544Z",
"updatedAt": "2024-09-10T03:53:54.544Z",
"role": "workflow:owner",
"workflowId": "s6zsznwVs6N4L2Hx",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:24:49.924Z",
"updatedAt": "2025-08-13T08:02:55.000Z",
"id": "UZTEpQ4MzFUgnieh",
"name": "webhook-qw",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO news_source (topic,summary,source_url,author,publish_time,news_uid,is_translate,status,language,news_web,author_head,news_type) VALUES {{ $json.news_data }};\n\nSET @last_insert_id = LAST_INSERT_ID();\n\nINSERT INTO news_url (url,thumbnail_url,type,status,news_id)\nVALUES {{ $json.urls_data }};\n\nCOMMIT;",
"options": {}
},
"id": "55521739-d69f-450f-9ec9-c7cfbfdec1f4",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1040,
400
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\n// console.log(info_data_list);\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += '\"'+info_data_list.title+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.summary+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.url+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.author+'\"';\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.publish_time+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.id+'\"';\nnews_item_data += ',';\nnews_item_data += '0';\nnews_item_data += ',';\nnews_item_data += '\"4\"';\nnews_item_data += ',';\nnews_item_data += '\"zh_cn\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.news_web+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.author_header+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.type+'\"';\nnews_item_data += ')';\nimages_url = info_data_list.images_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '4';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "13d38f15-173b-4bb7-8355-20d8c290b87b",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
780,
400
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "qw/translate/ch",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "634935f6-3a7e-41ac-9983-a8c46de0d808",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
520,
400
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "eb933193-7172-43b7-b12a-bbf4d88a5345",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:24:49.932Z",
"updatedAt": "2025-02-13T05:24:49.932Z",
"role": "workflow:owner",
"workflowId": "UZTEpQ4MzFUgnieh",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:26:27.831Z",
"updatedAt": "2025-04-07T11:29:34.000Z",
"id": "XOxxbzAyvGssVTZV",
"name": "webhook-theguardian",
"active": true,
"nodes": [
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-fxQiMsg03GrJCtwNfLRtnD4R\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"').replaceAll(/\\\\n/g, '')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_theguardian\"\n}",
"options": {}
},
"id": "2423e7cc-07ea-44a8-9c7f-482313383562",
"name": "dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
400,
280
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ntitle = JSON.parse($input.item.json.body.info).title;\ncontent = JSON.parse($input.item.json.body.info).content;\ntext_info['title'] = title;\n//text_info['content'] = content;\noutput_info['text'] = JSON.stringify(text_info);\nreturn output_info;"
},
"id": "9584a3ec-017f-4f42-adb5-ecdfaa9cead6",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
140,
280
]
},
{
"parameters": {
"mode": "runOnceForEachItem",
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n let missing = '';\n if (!str.endsWith('\"}')) {\n missing += '\"}'\n }\n str = str+missing;\n return str;\n}\n// answer = $input.item.json.data.outputs.result.answer;\n// answer = $input.item.json.data.answer;\nanswer = $input.item.json.answer;\nanswer = answer.replaceAll(/\\n/g, '').replaceAll(/%s| /g, '');\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nreturn answer_data;"
},
"id": "2d1dc138-7daf-4ed5-8d42-d5cd9ca46c1e",
"name": "get_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
680,
280
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO news_source (topic,content,source_url,news_uid,status,language,snapshot,news_web,news_type) VALUES {{ $json.news_data }};\n\nSET @last_insert_id = LAST_INSERT_ID();\n\nINSERT INTO news_url (url, type,news_id)\nVALUES {{ $json.urls_data }};\n\nCOMMIT;",
"options": {}
},
"id": "6507e1ec-dd11-48d2-94f6-0dc4a2d57cd5",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1200,
280
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('answer' in item_data){\n content_all['answer'] = item_data['answer'];\n }\n}\n//console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').item.json.body.info);\nanswer_data = content_all.answer;\ninfo_data_list['title'] = answer_data.title;\n//info_data_list['content'] = answer_data.content;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += '\"'+info_data_list.title+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.content+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.url+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.id+'\"';\nnews_item_data += ',';\nnews_item_data += '\"4\"';\nnews_item_data += ',';\nnews_item_data += '\"zh_cn\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.html_url+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.news_web+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.type+'\"';\nnews_item_data += ')';\nimages_url = info_data_list.images_url;\nfor (let i = 0; i < images_url.length; i++) {\n image_url = images_url[i];\n image_item_data = \"(\";\n image_item_data += '\"'+image_url+'\"';\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n}\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','',''),\"\n}\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "95f88b0d-d2bf-4c31-80cb-de4ccdf54cef",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
940,
280
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "theguardian/translate/ch",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "e343ac73-8e4a-4d93-a4f1-4d5561e85d75",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-120,
280
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"dify": {
"main": [
[
{
"node": "get_answer",
"type": "main",
"index": 0
}
]
]
},
"get_info": {
"main": [
[
{
"node": "dify",
"type": "main",
"index": 0
}
]
]
},
"get_answer": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "ecc05f57-c667-4542-8d91-4916590bc7ef",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:26:27.839Z",
"updatedAt": "2025-02-13T05:26:27.839Z",
"role": "workflow:owner",
"workflowId": "XOxxbzAyvGssVTZV",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-02-13T05:28:21.677Z",
"updatedAt": "2025-03-03T02:43:43.000Z",
"id": "H4chDgcmTQpVL9Ql",
"name": "webhook-twitter",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select location from schedule a where a.id = {{$('Webhook').item.json.body.schedule_id}};\n",
"options": {}
},
"id": "74d2db72-a3c9-434f-94ba-d5098f83756b",
"name": "get_location",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
60,
40
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nlet output_info = {};\nlet text_info = {};\ninfo = JSON.parse($('Webhook').item.json.body.info).full_text.replace(/https:\\/\\/[^\\s]+/g, '').replaceAll(/[ \\t\\n\\r]+/g, ' ').replaceAll(\"\\\"\", '” ');\nconsole.log(info);\nuser_id = JSON.parse($('Webhook').item.json.body.info).id;\ntext_info['full_text'] = info;\noutput_info['text'] = JSON.stringify(text_info);\noutput_info['msg_info'] = info;\noutput_info['user_id'] = user_id;\nreturn output_info;"
},
"id": "b1159cc1-1d2e-4ddb-b999-87c816c6405c",
"name": "get_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
-320,
-440
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_source({{ (JSON.stringify($json.data))}},{{ JSON.stringify(JSON.stringify($json.label_data)) }},{{ JSON.stringify(JSON.stringify($json.artificial_label_data)) }});",
"options": {}
},
"id": "3897d8b1-7614-45ff-9aa5-a6cc289973ac",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
820,
20
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('location' in item_data){\n content_all['location'] = item_data['location'];\n }else if('label_data' in item_data){\n content_all['label'] = item_data['label_data'];\n }else if('artificial_label_data' in item_data){\n content_all['artificial_label'] = item_data['artificial_label_data'];\n }\n};\nfunction containsChinese(str) {\n const chineseRegex = /[\\u4e00-\\u9fa5]/;\n return chineseRegex.test(str);\n};\n// console.log(content_all);\nlocation_data_list = JSON.parse(content_all.location);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\nlabel_data_list = content_all.label;\nartificial_label_data_list = content_all.artificial_label;\nif(artificial_label_data_list.length>0 && location_data_list.length>0){\n artificial_label_data_list[0]['city_code'] = location_data_list[0].cityCode;\n}\ninfo_data_list['full_text'] = info_data_list.full_text.replace(/https:\\/\\/[^\\s]+/g, '');\ntranster_answer_data = $('get_transter_answer').all()[0].json.answer.full_text;\ninfo_data_list['full_text_ch'] = transter_answer_data;\noutput_all = [];\noutput_all_data = {};\noutput_news_data_str = \"\";\noutput_news_url_data_str = \"\";\noutput_news_label_data_str = \"\";\nfull_text_new = info_data_list.full_text.replace(/'/g, \"\").replace(/\"/g, \"\");\nfull_text_ch_new = info_data_list.full_text_ch.replace(/'/g, \"\").replace(/\"/g, \"\");\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+full_text_new+\"'\";\nnews_item_data += ',';\nif(containsChinese(full_text_ch_new)){\n news_item_data += \"'\"+full_text_ch_new+\"'\";\n}else{\n news_item_data += \"'\"+full_text_new+\"'\";\n}\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.screen_name+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.profile_image_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'0'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.favourite_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.retweet_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.view_count+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'zh_cn'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.created_at+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'twitter'\";\nnews_item_data += ',';\nnews_item_data += \"'1'\";\nnews_item_data += ')';\nfor (let i = 0; i < location_data_list.length; i++) {\n city_code = location_data_list[i].cityCode;\n item_data = \"(\";\n item_data += \"'\"+city_code+\"'\";\n item_data += ',';\n item_data += '@last_insert_id';\n item_data += '),';\n output_news_data_str += item_data;\n};\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\noutput_all_data['city_data'] = output_news_data_str.slice(0,output_news_data_str.length-1);\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all_data_temp['label_data'] = label_data_list;\noutput_all_data_temp['artificial_label_data'] = artificial_label_data_list;\noutput_all.push(output_all_data_temp);\nreturn output_all;"
},
"id": "794a0f6a-5232-4935-aa62-fe76966e21ce",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
560,
20
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "11b566db-86fa-4bc8-b29e-41126bc52997",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
-600,
60
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }};\n",
"options": {}
},
"id": "f6218dfd-1cfb-4c97-b5b9-b28a7eec50d0",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
-840,
60
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/completion-messages",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-KRXKS2lXohYjnIKmuYxSncem\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"record_json\":\"{{$json.text.replaceAll(/\"/g, '\\\\\"')}}\",\"language\":\"中文\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "de50700e-6d6c-427f-9fa7-6e05e81780fd",
"name": "translate_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
-140,
-440
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\nfunction isEmpty(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value) {\n return true;\n }\n return false;\n};\nlabel_data_list = [];\nartificial_label_data_list = [];\nlabel_data_arr = $input.all();\nlabel_result_list = [];\nartificial_label_result_list = [];\nfor(var label_index=0;label_index<label_data_arr.length;label_index++){\n label_data_temp = label_data_arr[label_index];\n workflow_id = label_data_temp.json.data.workflow_id;\n label_data_output_list = label_data_temp.json.data.outputs;\n if(workflow_id == '767511d7-ccf6-42c1-a42e-b2c14959c147'){\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n for (let i = 0; i < label_result.length; i++) {\n label_result_list.push(label_result[i]);\n }\n }\n }else{\n if(!isEmpty(label_data_output_list)){\n label_result = label_data_output_list.result;\n let label_index_temp = 0;\n for (let i = 0; i < label_result.length&&label_index_temp<1; i++) {\n artificial_label_result_list.push(label_result[i]);\n label_index_temp += 1;\n }\n } \n }\n};\n// console.log(label_result_list);\nfor (let i = 0; i < label_result_list.length; i++) {\n label_code_score = {};\n label_code = label_result_list[i].code;\n label_score = label_result_list[i].score;\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['score'] = label_score;\n label_data_list.push(label_code_score);\n }\n};\nfor (let i = 0; i < artificial_label_result_list.length; i++) {\n label_code_score = {};\n label_code = artificial_label_result_list[i].code;\n label_name = artificial_label_result_list[i].name;\n label_score = artificial_label_result_list[i].score;\n if(!isEmptyString(label_code)){\n label_code_score['code'] = label_code;\n label_code_score['name'] = label_name;\n label_code_score['score'] = label_score;\n artificial_label_data_list.push(label_code_score);\n }\n};\nlabel_data_list_2 = [];\nlabel_data_json = {};\nartificial_label_data_json = {};\nlabel_data_json[\"label_data\"] = label_data_list;\nartificial_label_data_json[\"artificial_label_data\"] = artificial_label_data_list;\n// console.log(label_data_json);\nlabel_data_list_2.push(label_data_json);\nlabel_data_list_2.push(artificial_label_data_json);\nreturn label_data_list_2;"
},
"id": "5b10b3af-25b8-4c85-b26f-f0cc1a825c60",
"name": "get_label_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
820,
-320
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\n//answer = \"```json{\\\"test1\\\":\\\"test\\\"}```\";\nfunction findAllIndexes(str, charToFind) {\n const regex = new RegExp(charToFind, 'g');\n let indexes = [];\n let result;\n while ((result = regex.exec(str)) !== null) {\n indexes.push(result.index);\n }\n return indexes;\n}\nfunction isValidJSON(str) {\n try {\n JSON.parse(str);\n return true;\n } catch (e) {\n return false;\n }\n}\nfunction autoCompleteJSON(str) {\n if (isValidJSON(str)) {\n return str;\n }\n if (!str.includes('\"}') || (str.includes('\"}') && !str.endsWith('\"}'))) {\n str = str.replaceAll(\"}\",\"\");\n }\n str = retainSingleOccurrence(str,'}');\n // console.log(str);\n let missing = '';\n if (!str.endsWith('\"}')) {\n if (str.endsWith('\"')) {\n missing += '}'\n }else{\n missing += '\"}'\n }\n }\n str = str+missing;\n // console.log(str);\n return str;\n}\nfunction retainSingleOccurrence(str, subStr) {\n // 检查字符串是否包含子字符串\n if (!str.includes(subStr)) {\n return str;\n }\n // 使用正则表达式删除多余的子字符串\n // 使用全局匹配标志 g 和正则表达式来匹配所有子字符串\n // 注意:这里假设子字符串不会与其他文本重叠\n const regex = new RegExp(`(${subStr})(?=.*${subStr})`, 'g');\n let result = str.replace(regex, '');\n return result;\n}\nanswer =$input.all()[0].json.answer;\nindexes = findAllIndexes(answer,\"```\");\nanswer_str = '';\nif(indexes.length>0){\n answer_str = answer.slice(indexes[0]+7, indexes[1]);\n}else{\n answer_str = answer;\n}\nanswer_str = answer_str.replace(/\\s+/g, '');\nanswer_data_json = JSON.parse(autoCompleteJSON(answer_str));\nanswer_data = {};\nanswer_data[\"answer\"] = answer_data_json;\nreturn answer_data;"
},
"id": "debaa6fe-dfcc-479b-9297-0482ec381f2b",
"name": "get_transter_answer",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
40,
-440
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-SRHXAMF0iYxuCJD5cnHYgtJZ\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$('get_info').item.json.msg_info.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "5a315637-5310-4232-b066-89cfc863f80b",
"name": "natural_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
300,
-320
]
},
{
"parameters": {
"method": "POST",
"url": "http://172.31.0.160/v1/workflows/run",
"sendHeaders": true,
"specifyHeaders": "json",
"jsonHeaders": "{\n \"Authorization\": \"Bearer app-HCbsiZmUCzP8Vdqb2meKXQSb\",\n \"Content-Type\": \"application/json\"\n}",
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"inputs\": {\"msg_info\":\"{{$json.answer.full_text.replaceAll(/\"/g, '\\\\\"')}}\"},\n \"response_mode\": \"blocking\",\n \"user\": \"sl_backend_twitter\"\n}",
"options": {}
},
"id": "daf8b31b-3807-419c-911f-48f118fffe9c",
"name": "artificial_label_dify",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [
300,
-520
]
},
{
"parameters": {},
"id": "c768f7e1-4135-4977-89c0-496420a65a5d",
"name": "merge_label",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
520,
-420
]
},
{
"parameters": {},
"id": "b90aad45-fd1c-41ad-a960-fe35464b4928",
"name": "get_answer_location",
"type": "n8n-nodes-base.merge",
"typeVersion": 3,
"position": [
300,
20
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select location from schedule a where a.id = {{$('Webhook').item.json.body.schedule_id}};\n",
"options": {}
},
"id": "d36438f8-a797-48cc-b86c-6fa0e7469858",
"name": "get_city_code",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
60,
320
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\nfor(let item_index =0; item_index < result_data.length;item_index++){\n item_data = result_data[item_index].json;\n if('location' in item_data){\n content_all['location'] = item_data['location'];\n }\n};\nlocation_data_list = JSON.parse(content_all.location);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\noutput_news_data_str = '';\noutput_all_data = {};\noutput_all = [];\noutput_city_code_list = [];\nfor (let i = 0; i < location_data_list.length; i++) {\n city_code = location_data_list[i].cityCode;\n output_city_code_list.push(city_code);\n};\noutput_all_data['city_code'] = output_city_code_list;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all.push(output_all_data);\nconsole.log(output_all);\nreturn output_all;"
},
"id": "4a398fa1-14b6-4fc3-a25a-fbb00b6f70b9",
"name": "get_city_code_info",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
300,
320
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_news_city({{ JSON.stringify(JSON.stringify($json.city_code))}},{{ JSON.stringify(JSON.stringify($json.news_id)) }});",
"options": {}
},
"id": "585832d9-f409-4de0-ab52-f91e60bfa620",
"name": "insert_city_data",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
560,
320
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"operation": "executeQuery",
"query": "update news_source set likes = {{ JSON.parse( $('Webhook').item.json.body.info).favourite_count }} ,forward = {{ JSON.parse( $('Webhook').item.json.body.info).retweet_count }},hot = {{ JSON.parse( $('Webhook').item.json.body.info).view_count }} where news_uid = {{ JSON.stringify(JSON.parse( $('Webhook').item.json.body.info).id) }}\n",
"options": {}
},
"id": "001fba39-1aec-4c4e-905f-51e3476f4bd8",
"name": "update_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
60,
560
],
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "twitter/translate/ch",
"authentication": "headerAuth",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "c5626b71-d366-4b9b-9239-aacdecefdb5b",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-1100,
60
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"get_location": {
"main": [
[
{
"node": "get_answer_location",
"type": "main",
"index": 1
}
]
]
},
"get_info": {
"main": [
[
{
"node": "translate_dify",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_info",
"type": "main",
"index": 0
},
{
"node": "get_location",
"type": "main",
"index": 0
}
],
[
{
"node": "get_city_code",
"type": "main",
"index": 0
},
{
"node": "update_city_news",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"translate_dify": {
"main": [
[
{
"node": "get_transter_answer",
"type": "main",
"index": 0
}
]
]
},
"get_label_answer": {
"main": [
[
{
"node": "get_answer_location",
"type": "main",
"index": 0
}
]
]
},
"get_transter_answer": {
"main": [
[
{
"node": "artificial_label_dify",
"type": "main",
"index": 0
},
{
"node": "natural_label_dify",
"type": "main",
"index": 0
}
]
]
},
"natural_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 1
}
]
]
},
"artificial_label_dify": {
"main": [
[
{
"node": "merge_label",
"type": "main",
"index": 0
}
]
]
},
"merge_label": {
"main": [
[
{
"node": "get_label_answer",
"type": "main",
"index": 0
}
]
]
},
"get_answer_location": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
]
]
},
"get_city_code": {
"main": [
[
{
"node": "get_city_code_info",
"type": "main",
"index": 0
}
]
]
},
"get_city_code_info": {
"main": [
[
{
"node": "insert_city_data",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "ab517b8c-61ab-4131-a4d2-d23c88ecf2b9",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-02-13T05:28:21.685Z",
"updatedAt": "2025-02-13T05:28:21.685Z",
"role": "workflow:owner",
"workflowId": "H4chDgcmTQpVL9Ql",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-04-29T10:34:49.830Z",
"updatedAt": "2025-04-29T10:36:28.000Z",
"id": "zzrL2FuRTM6pe1zY",
"name": "worldnews_is_exists",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from news_source where news_uid ={{JSON.stringify(JSON.parse($json.body.info).id) }} and news_type = 0;\n",
"options": {}
},
"id": "8596f772-c1e3-48bb-a339-9694c5d37b90",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
1040,
320
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "YpVIiGwzmmkf7vR7",
"name": "SL-DB-PRD"
}
}
},
{
"parameters": {
"httpMethod": "POST",
"path": "worldnews/isexistsbynewsid",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "682a9896-cc9a-4f36-bb6a-ace19402a4f0",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
780,
320
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "142063d5-0eaf-4af8-a3b4-1a6f01d7e2c7",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-04-29T10:34:49.842Z",
"updatedAt": "2025-04-29T10:34:49.842Z",
"role": "workflow:owner",
"workflowId": "zzrL2FuRTM6pe1zY",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-05-12T08:19:41.822Z",
"updatedAt": "2025-07-16T07:09:57.000Z",
"id": "jNCkhUhSAy7naaEb",
"name": "xhs_notes_record",
"active": true,
"nodes": [
{
"parameters": {
"operation": "executeQuery",
"query": "CALL insert_notes_source({{ (JSON.stringify($json.data))}});",
"options": {}
},
"id": "a8575fc1-564c-466f-91ff-c86c7df28496",
"name": "insert_city_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
900,
400
],
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\ncontent_all = {};\n// console.log(result_data);\n// console.log(content_all);\ninfo_data_list = JSON.parse($('Webhook').all()[0].json.body.info);\nschedule_id = $('Webhook').all()[0].json.body.schedule_id;\noutput_all = [];\noutput_all_data = {};\noutput_news_url_data_str = \"\";\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += \"'\"+info_data_list.title+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.content+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.source_content+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.source_url+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.author+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.author_head+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.likes+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.forward+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.hot+\"'\";\nnews_item_data += ',';\nnews_item_data += 'STR_TO_DATE(\\''+info_data_list.publish_time+'\\',\\'%Y-%m-%d %H:%i:%s\\')';\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.note_uid+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+schedule_id+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.note_source+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.keywords+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.tags+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.note_type+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.keywords_code+\"'\";\nnews_item_data += ',';\nnews_item_data += \"'\"+info_data_list.location+\"'\";\nnews_item_data += ')';\nimages_url = info_data_list.images_url;\nvideos_url = info_data_list.videos_url;\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() == '' || value.trim() == 'null' || value.trim() == 'None') {\n return true;\n }\n return false;\n};\nfor (let i = 0; i < images_url.length; i++) {\n image_url_data = images_url[i];\n original_url = image_url_data.original_url;\n thumbnail_url = image_url_data.thumbnail_url;\n if(isEmptyString(original_url) && isEmptyString(thumbnail_url)){\n continue;\n }else{\n image_item_data = \"(\";\n image_item_data += \"'\"+original_url+\"'\";\n image_item_data += ',';\n if(isEmptyString(thumbnail_url)){\n image_item_data += null;\n }else{\n image_item_data += \"'\"+thumbnail_url+\"'\";\n }\n image_item_data += ',';\n image_item_data += '0';\n image_item_data += ',';\n image_item_data += '4';\n image_item_data += ',';\n image_item_data += '@last_insert_id';\n image_item_data += '),';\n output_news_url_data_str += image_item_data;\n }\n};\nfor (let i = 0; i < videos_url.length; i++) {\n video_url = videos_url[i];\n video_item_data = \"(\";\n video_item_data += \"'\"+video_url+\"'\";\n video_item_data += ',';\n video_item_data += null;\n video_item_data += ',';\n video_item_data += '2';\n video_item_data += ',';\n video_item_data += '4';\n video_item_data += ',';\n video_item_data += '@last_insert_id';\n video_item_data += '),';\n output_news_url_data_str += video_item_data;\n};\nif(output_news_url_data_str.length == 0){\n output_news_url_data_str = \"('','','',''),\"\n}\n\noutput_all_data['urls_data'] = output_news_url_data_str.slice(0,output_news_url_data_str.length-1);\noutput_all_data['news_data'] = news_item_data;\noutput_all_data['news_id'] = info_data_list.id;\noutput_all_data_temp = {};\noutput_all_data_temp['data'] = JSON.stringify(output_all_data);\noutput_all.push(output_all_data_temp);\nconsole.log(JSON.stringify(output_all_data));\nreturn output_all;"
},
"id": "061df719-28a5-4f81-adb3-a6bbd1acf3e1",
"name": "get_city_news_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
400
]
},
{
"parameters": {
"conditions": {
"options": {
"caseSensitive": true,
"leftValue": "",
"typeValidation": "strict"
},
"conditions": [
{
"id": "a1541edc-9637-4ac2-83a6-902ee9d29af6",
"leftValue": "={{ $json.count.toString() }}",
"rightValue": "=0",
"operator": {
"type": "string",
"operation": "equals"
}
}
],
"combinator": "and"
},
"options": {}
},
"id": "e231b1a1-c4bb-4fac-86cf-693cbf627dc8",
"name": "insert_or_update",
"type": "n8n-nodes-base.if",
"typeVersion": 2,
"position": [
380,
680
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "select IFNULL(count(id), 0) as count from notes_info where note_uid ={{JSON.stringify(JSON.parse($json.body.info).note_uid) }};\n",
"options": {}
},
"id": "a7dd5d25-16fc-44d9-ab81-bce8bd2c076a",
"name": "is_exists_news",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
140,
680
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "09oRI0DULmEzD9l8",
"name": "SL-DB"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '1';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "6f642ff4-0d8f-4056-bcb2-7d83f01cec47",
"name": "return_save_flag",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
1140,
400
]
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nresult_data = $input.all();\noutput_all_data = {};\noutput_all = [];\noutput_all_data['is_save'] = '0';\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "b50c43c5-80ac-4441-a53f-7f701bbe8e68",
"name": "return_result",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
640,
700
]
},
{
"parameters": {
"httpMethod": "POST",
"path": "xhs/save",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "c5ce2e41-6298-4ad9-8c0c-a00a7d792113",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
-120,
680
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
}
],
"connections": {
"insert_city_news": {
"main": [
[
{
"node": "return_save_flag",
"type": "main",
"index": 0
}
]
]
},
"get_city_news_sql": {
"main": [
[
{
"node": "insert_city_news",
"type": "main",
"index": 0
}
]
]
},
"insert_or_update": {
"main": [
[
{
"node": "get_city_news_sql",
"type": "main",
"index": 0
}
],
[
{
"node": "return_result",
"type": "main",
"index": 0
}
]
]
},
"is_exists_news": {
"main": [
[
{
"node": "insert_or_update",
"type": "main",
"index": 0
}
]
]
},
"Webhook": {
"main": [
[
{
"node": "is_exists_news",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "dfaf21eb-490a-4a46-9386-bcedae2a0c91",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-05-12T08:19:41.837Z",
"updatedAt": "2025-05-12T08:19:41.837Z",
"role": "workflow:owner",
"workflowId": "jNCkhUhSAy7naaEb",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
{
"createdAt": "2025-05-16T15:11:32.033Z",
"updatedAt": "2025-05-19T02:58:15.000Z",
"id": "OVJrtC4XBByRmg1M",
"name": "xhs_sms_code_send",
"active": true,
"nodes": [
{
"parameters": {
"httpMethod": "POST",
"path": "code/send",
"authentication": "headerAuth",
"responseMode": "lastNode",
"options": {
"allowedOrigins": "*",
"rawBody": false
}
},
"id": "33b0204b-ea6b-4549-b363-59d1ce6ca11e",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [
140,
260
],
"webhookId": "e495a29c-8f43-4175-bdb8-277e03b60b07",
"credentials": {
"httpHeaderAuth": {
"id": "U87Wvnvu9oQ5Zapo",
"name": "Header Auth account"
}
}
},
{
"parameters": {
"jsCode": "// Loop over input items and add a new field called 'myNewField' to the JSON of each one\nfunction isEmptyString(value) {\n // 方法1: 直接检查是否为空字符串或null\n if (!value || value.trim() === '') {\n return true;\n }\n return false;\n};\ninfo_data_list = JSON.parse($('Webhook').item.json.body.payload);\ncontent = info_data_list.text;\ncontent_data_arr = content.split(\":\");\ncode = content_data_arr[1].split(\"\")[0].trim();\noutput_all = [];\noutput_all_data = {};\nnews_item_data = \"\";\nnews_item_data = news_item_data+\"(\";\nnews_item_data += '\"'+info_data_list.sjh+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+info_data_list.app_version+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+code+'\"';\nnews_item_data += ',';\nnews_item_data += '\"'+content+'\"';\nnews_item_data += ',';\nif(!isEmptyString(info_data_list.receive_time)){\n news_item_data += 'STR_TO_DATE(\"'+info_data_list.receive_time+'\",\"%Y-%m-%d %H:%i:%s\")';\n}else{\n news_item_data += 'STR_TO_DATE(NOW(),\"%Y-%m-%d %H:%i:%s\")';\n};\nnews_item_data += ')';\noutput_all_data['sms_data'] = news_item_data;\noutput_all.push(output_all_data);\nreturn output_all;"
},
"id": "810f2550-bd45-4c81-b1d1-feb72162d84f",
"name": "get_sms_code_sql",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
400,
260
]
},
{
"parameters": {
"operation": "executeQuery",
"query": "START TRANSACTION;\n\nINSERT INTO xhs_sms_code (sjh,app_version,code,content,receive_time) VALUES {{ $json.sms_data }};\nCOMMIT;",
"options": {}
},
"id": "7ede50c1-8fbf-4f1f-8d93-8bc786fb7bcc",
"name": "save_sms_code",
"type": "n8n-nodes-base.mySql",
"typeVersion": 2.4,
"position": [
660,
260
],
"alwaysOutputData": false,
"credentials": {
"mySql": {
"id": "weDnmTLkKsAyzDPl",
"name": "MYB_SQL_TEST"
}
}
}
],
"connections": {
"Webhook": {
"main": [
[
{
"node": "get_sms_code_sql",
"type": "main",
"index": 0
}
]
]
},
"get_sms_code_sql": {
"main": [
[
{
"node": "save_sms_code",
"type": "main",
"index": 0
}
]
]
}
},
"settings": {
"executionOrder": "v1"
},
"staticData": null,
"meta": {
"templateCredsSetupCompleted": true
},
"pinData": {},
"versionId": "c0f3d684-b3a5-4761-a752-407221c5a444",
"triggerCount": 1,
"shared": [
{
"createdAt": "2025-05-16T15:11:32.048Z",
"updatedAt": "2025-05-16T15:11:32.048Z",
"role": "workflow:owner",
"workflowId": "OVJrtC4XBByRmg1M",
"projectId": "C7zKoCDdmGgzUqSW",
"project": {
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:41:43.608Z",
"id": "C7zKoCDdmGgzUqSW",
"name": "周 卫 <zhouwei@ssish.com>",
"type": "personal",
"projectRelations": [
{
"createdAt": "2024-08-23T06:31:21.275Z",
"updatedAt": "2024-08-23T06:31:21.275Z",
"role": "project:personalOwner",
"userId": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"projectId": "C7zKoCDdmGgzUqSW",
"user": {
"createdAt": "2024-08-23T06:31:16.119Z",
"updatedAt": "2025-03-19T06:19:26.514Z",
"id": "3f0021b4-d0a7-4db6-af21-5ef829c47882",
"email": "zhouwei@ssish.com",
"firstName": "周",
"lastName": "卫",
"personalizationAnswers": {
"companyType": "education",
"role": "business-owner",
"automationBeneficiary": "my-team",
"companySize": "20-99",
"reportedSource": "friend",
"version": "v4",
"personalization_survey_submitted_at": "2024-08-23T06:57:52.856Z",
"personalization_survey_n8n_version": "1.55.3"
},
"settings": {
"userActivated": true,
"firstSuccessfulWorkflowId": "s6zsznwVs6N4L2Hx",
"userActivatedAt": 1725957335278,
"npsSurvey": {
"responded": true,
"lastShownAt": 1742365155724
},
"isOnboarded": true
},
"role": "global:owner",
"disabled": false,
"mfaEnabled": false,
"isPending": false,
"isOwner": true
}
}
]
}
}
],
"tags": []
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment