{
  "name": "TikTok Follower Count on Clock",
  "nodes": [
    {
      "parameters": {
        "method": "POST",
        "url": "http://192.168.178.139/api/custom",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "tiktok"
            }
          ]
        },
        "options": {
          "contentType": "json"
        },
        "sendBody": true,
        "jsonParameters": true,
        "bodyParametersJson": "={\"text\": $json[\"text\"], \"icon\": 35685, \"duration\": 8}"
      },
      "id": "1f69869a-7873-493e-a7e0-a9394476cd5c",
      "name": "Remove App",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        1080,
        280
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "hoursInterval": 12
            }
          ]
        }
      },
      "id": "5edff45f-0d97-4b2e-91ef-256e2714f4cd",
      "name": "Every 12 Hours",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        680,
        460
      ]
    },
    {
      "parameters": {
        "url": "https://www.tiktok.com/@yourusernamehere",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "User-Agent",
              "value": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0"
            }
          ]
        },
        "options": {
          "responseFormat": "string"
        }
      },
      "id": "b658c902-70c6-473e-bc5f-b7dba83c9b4d",
      "name": "Fetch HTML Data",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        880,
        460
      ]
    },
    {
      "parameters": {
        "jsCode": "// Holt das HTML aus unterschiedlichen Feldern (je nach HTTP-Node-Einstellung)\nconst html =\n  (items[0]?.json?.data) ??\n  (items[0]?.json?.body) ??\n  (typeof items[0]?.json === 'string' ? items[0].json : '') ??\n  '';\n\n// Short-Formatter für AWTRIX (12.3K / 1.2M)\nfunction short(n) {\n  if (n == null || isNaN(n)) return 'N/A';\n  if (n >= 1_000_000) return (Math.round(n / 100_000) / 10) + 'M';\n  if (n >= 1_000)     return (Math.round(n / 100) / 10) + 'K';\n  return String(n);\n}\n\nlet followerCount = null;\nlet m;\n\n// 1) Bevorzugt: statsV2.followerCount (String oder Zahl)\nm = /\"statsV2\"\\s*:\\s*\\{[^}]*?\"followerCount\"\\s*:\\s*\"?(\\d+)\"?/s.exec(html);\nif (m) followerCount = Number(m[1]);\n\n// 2) Generischer JSON-Treffer: \"followerCount\": 1362 oder \"followerCount\":\"1362\"\nif (followerCount == null) {\n  m = /\"followerCount\"\\s*:\\s*\"?(\\d+)\"?/.exec(html);\n  if (m) followerCount = Number(m[1]);\n}\n\n// 3) HTML-Tag: <strong data-e2e=\"followers-count\">1362</strong>\nif (followerCount == null) {\n  const strongRe = /<strong[^>]*data-e2e=[\"']followers-count[\"'][^>]*>([\\d\\.\\,\\s]+)<\\/strong>/i;\n  const ms = strongRe.exec(html);\n  if (ms) {\n    const raw = ms[1].replace(/[^\\d]/g, '');\n    if (raw) followerCount = Number(raw);\n  }\n}\n\n// Ergebnis für AWTRIX aufbereiten\nconst out = {\n  followerCount: followerCount ?? null,\n  text: short(followerCount)\n};\n\n// n8n-Code-Node erwartet ein Array von Items\nreturn [{ json: out }];\n"
      },
      "id": "77e52f14-4f12-494a-a6ef-b8099cdbaef5",
      "name": "Extract Follower Count",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        1080,
        460
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "http://192.168.178.139/api/custom",
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "name",
              "value": "tiktok"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "text",
              "value": "={{ $json.followerCount }}"
            },
            {
              "name": "icon",
              "value": "35685"
            }
          ]
        },
        "options": {
          "contentType": "json"
        },
        "jsonParameters": true,
        "bodyParametersJson": "={\"text\": $json[\"text\"], \"icon\": 35685, \"duration\": 8}"
      },
      "id": "2ac10d71-31a8-414c-887a-9dba5e163915",
      "name": "Send to Clock",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        1280,
        460
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Every 12 Hours": {
      "main": [
        [
          {
            "node": "Fetch HTML Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch HTML Data": {
      "main": [
        [
          {
            "node": "Extract Follower Count",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Follower Count": {
      "main": [
        [
          {
            "node": "Send to Clock",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {},
  "versionId": "16b1e879-3e36-490c-954d-f93cce32c815",
  "id": "6",
  "meta": {
    "instanceId": "fad48ee50ab295e27486d400f427ed5b50baff0c1dc235dc9413ccebae5358c7"
  },
  "tags": []
}