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