{ "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_index0){\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": "周 卫 ", "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": [] }