logoalt Hacker News

gloosxtoday at 8:32 AM0 repliesview on HN

Hello OP, I think using an ai agent to fetch the JSON is a bit of an overkill

Here is a node.js script for you which will fetch the data and save it to the file:

  import fs from 'fs'
  import puppeteer from 'puppeteer-extra'
  import StealthPlugin from 'puppeteer-extra-plugin-stealth'
  puppeteer.use(StealthPlugin())

  const browser = await puppeteer.launch();
  const page = await browser.newPage();

  async function fetchCoords(x, y, z = 8, station = 0) {
    await  page.goto(`https://www.marinetraffic.com/getData/get_data_json_4/z:${z}/X:${x}/Y:${y}/station:${station}`);

    const jsonRaw = await page.evaluate(() => document.body.innerText);

    const json = JSON.parse(jsonRaw)

    return json
  }

  const data8353 = await fetchCoords(83, 53)

  const data8453 = await fetchCoords(84, 53)

  const data8354 = await fetchCoords(83, 54)

  const data8454 = await fetchCoords(84, 54)

  const fullData = { ...data8353, ...data8453, ...data8354, ...data8454 }

  fs.writeFileSync('data.json', JSON.stringify(fullData, null, 2))

  console.log('done!')

  process.exit(0)

Just like this, no need to spend a cent on expensive APIs or tokens