require('dotenv').config() const cron = require('cron') const apis = require('./libs/apis.js') const crawler = require('./libs/crawler.js') const runIGLook = async () => { let ids = await apis.GetInstagramIDs() console.log('all ids :: ', ids) if (ids === null || !Array.isArray(ids) || ids.length === 0) return ids.forEach(t => { getPost(t) }) } const getPost = async (id) => { console.log('get instagram :: ', id) let post = await crawler.getLastPost(id) console.log(`get post data ::: ${post.id} / ${post.text} / ${post.link} / ${post.timestamp}`) let minTime = Math.floor(Date.now() / 1000) - 1800 if (minTime > post.timestamp) return let data = { id, post_id: post.id, text: post.text, link: post.link } await apis.SendPostData([data]) } // set fblook new cron.CronJob({ //eslint-disable-line cronTime: '00 */2 * * * *', onTick: async () => { console.log('Start Tick') try { await runIGLook() } catch (err) { console.log('run tick fail', err) } }, runOnInit: true, start: true, timeZone: 'Asia/Taipei' })