Files
FarmaFinder/n8n/workflows/parapharmacy-scraper.json
T
Antoni Nuñez Romeu b4b2bf5834
Run Tests on Branches / Detect Changes (push) Successful in 12s
Run Tests on Branches / Backend Tests (push) Has been skipped
Run Tests on Branches / Frontend Tests (push) Has been skipped
Run Tests on Branches / Frontend Mobile Tests (push) Has been skipped
Run Tests on Branches / Parapharmacy API Tests (push) Has been skipped
Run Tests on Branches / PIP Platform Tests (push) Has been skipped
fix(n8n): resolve duplicate key constraint on tag_entity during workflow import
n8n import:workflow --separate imports each JSON file independently. All 4
workflows shared the same tags (parapharmacy, scraper), so the second import
tried to INSERT duplicate tag names, hitting the unique index on
tag_entity.name.

- Remove tags field from all 4 workflow JSON files (cosmetic, re-add via UI)
- Add cleanup-db.js to wipe workflow data before import
- Add --overwrite flag to import command as safety net
- Add cleanup-db.js volume mount to n8n-init container
2026-07-17 14:50:35 +02:00

175 lines
4.8 KiB
JSON

{
"name": "Parapharmacy Scraper",
"nodes": [
{
"parameters": {
"rule": {
"interval": [
{
"field": "cronExpression",
"expression": "0 2 */3 * *"
}
]
}
},
"id": "schedule-trigger",
"name": "Schedule (Every 3 days at 2am)",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.2,
"position": [220, 300]
},
{
"parameters": {
"values": {
"string": [
{
"name": "queries",
"value": "crema hidratante cara,protector solar,leche corporal,champú bebé,aceite bebé,crema pañal,vitaminas bebé,formula lactea"
}
]
},
"options": {}
},
"id": "set-queries",
"name": "Set Search Queries",
"type": "n8n-nodes-base.set",
"typeVersion": 3.4,
"position": [440, 300]
},
{
"parameters": {
"fieldToSplitOut": "queries",
"options": {}
},
"id": "split-queries",
"name": "Split Queries",
"type": "n8n-nodes-base.splitOut",
"typeVersion": 1,
"position": [660, 300]
},
{
"parameters": {
"method": "GET",
"url": "https://www.promofarma.com/es/search?q={{ encodeURIComponent($json.queries) }}",
"options": {
"timeout": 30000
}
},
"id": "scrape-promofarma",
"name": "Scrape Promofarma",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [880, 200]
},
{
"parameters": {
"jsCode": "// Extract products from Promofarma HTML\nconst html = $input.first().json.data;\nconst products = [];\n\n// Simple regex extraction (adjust selectors based on actual HTML)\nconst productRegex = /<div class=\"product-card[^\"]*\"[^>]*>([\\s\\S]*?)<\\/div>/gi;\nconst nameRegex = /<h3[^>]*>([^<]+)<\\/h3>/i;\nconst priceRegex = /class=\"price[^\"]*\"[^>]*>([^<]+)<\\/span>/i;\nconst linkRegex = /<a[^>]*href=\"([^\"]+)\"[^>]*>/i;\n\nlet match;\nwhile ((match = productRegex.exec(html)) !== null) {\n const card = match[1];\n const name = nameRegex.exec(card)?.[1]?.trim();\n const price = priceRegex.exec(card)?.[1]?.trim();\n const link = linkRegex.exec(card)?.[1];\n \n if (name) {\n products.push({\n name,\n price: parseFloat(price?.replace(/[^\\d.,]/g, '').replace(',', '.')) || 0,\n source_url: link?.startsWith('http') ? link : `https://www.promofarma.com${link}`,\n source: 'promofarma',\n source_product_id: link?.match(/\\/p\\/([^/]+)/)?.[1] || Date.now().toString()\n });\n }\n}\n\nreturn products.map(p => ({ json: p }));"
},
"id": "extract-promofarma",
"name": "Extract Products",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [1100, 200]
},
{
"parameters": {
"method": "POST",
"url": "http://parapharmacy-api:3002/api/products/bulk",
"sendBody": true,
"bodyParameters": {
"parameters": []
},
"specifyBody": "json",
"jsonBody": "={{ JSON.stringify({ products: $input.all().map(item => item.json) }) }}",
"options": {}
},
"id": "send-to-api",
"name": "Send to Parapharmacy API",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [1320, 200]
},
{
"parameters": {},
"id": "no-operation",
"name": "No Op",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [1540, 200]
}
],
"connections": {
"Schedule (Every 3 days at 2am)": {
"main": [
[
{
"node": "Set Search Queries",
"type": "main",
"index": 0
}
]
]
},
"Set Search Queries": {
"main": [
[
{
"node": "Split Queries",
"type": "main",
"index": 0
}
]
]
},
"Split Queries": {
"main": [
[
{
"node": "Scrape Promofarma",
"type": "main",
"index": 0
}
]
]
},
"Scrape Promofarma": {
"main": [
[
{
"node": "Extract Products",
"type": "main",
"index": 0
}
]
]
},
"Extract Products": {
"main": [
[
{
"node": "Send to Parapharmacy API",
"type": "main",
"index": 0
}
]
]
},
"Send to Parapharmacy API": {
"main": [
[
{
"node": "No Op",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {
"executionOrder": "v1"
},
"versionId": "1"
}