|
const axios = require('axios'); |
|
const http = require('http'); |
|
const cron = require('node-cron'); |
|
const port = process.env.PORT || 7860; |
|
const moment = require('moment-timezone'); |
|
|
|
|
|
const urls = [ |
|
|
|
|
|
|
|
'https://www.yahoo.com', |
|
'https://discovered-ajar-kilogram.glitch.me', |
|
'https://butternut-purring-licorice.glitch.me', |
|
'https://bubble-towering-freedom.glitch.me', |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
]; |
|
|
|
|
|
function visitWebsites() { |
|
const websites = [ |
|
|
|
|
|
|
|
|
|
'https://unexpected-eager-dragon.glitch.me', |
|
'https://marvelous-zippy-golf.glitch.me', |
|
'https://chrome-bald-ship.glitch.me', |
|
'https://midi-outstanding-flea.glitch.me', |
|
'https://marvelous-plume-helium.glitch.me', |
|
'https://instinctive-night-honey.glitch.me', |
|
'https://evening-wheat-pecorino.glitch.me', |
|
'https://kindhearted-colorful-alfalfa.glitch.me', |
|
'https://early-lead-shampoo.glitch.me', |
|
'https://indigo-hickory-ear.glitch.me', |
|
'https://living-dented-rutabaga.glitch.me', |
|
'https://luxurious-historical-cycle.glitch.me', |
|
'https://leather-upbeat-gate.glitch.me', |
|
'https://magenta-able-asparagus.glitch.me', |
|
'https://checker-jumbled-helmet.glitch.me', |
|
'https://climbing-transparent-event.glitch.me', |
|
'https://lopsided-keen-celsius.glitch.me', |
|
'https://nosy-reliable-echo.glitch.me', |
|
'https://acidic-spiral-kryptops.glitch.me', |
|
'https://endurable-prickly-busby.glitch.me', |
|
'https://mint-young-angelfish.glitch.me', |
|
'https://stirring-bronze-growth.glitch.me', |
|
'https://abounding-roasted-hardware.glitch.me', |
|
'https://telling-rhetorical-thunder.glitch.me', |
|
'https://sincere-mellow-ketchup.glitch.me', |
|
'https://jungle-sordid-sunfish.glitch.me', |
|
'https://overjoyed-bedecked-flavor.glitch.me', |
|
'https://boom-grass-vulcanodon.glitch.me', |
|
'https://harvest-regal-puppy.glitch.me', |
|
'https://silver-waiting-fin.glitch.me', |
|
'https://diagnostic-apple-guide.glitch.me', |
|
'https://relieved-climbing-chard.glitch.me', |
|
'https://rhetorical-wobbly-asteroid.glitch.me', |
|
'https://solar-rainy-ixia.glitch.me', |
|
'https://irradiated-cooing-loan.glitch.me', |
|
'https://valuable-slime-bream.glitch.me', |
|
'https://flashy-basalt-jute.glitch.me', |
|
'https://short-tree-broker.glitch.me', |
|
'https://flicker-shiny-list.glitch.me', |
|
'https://acute-silky-college.glitch.me', |
|
'https://tough-voracious-dracopelta.glitch.me', |
|
'https://destiny-typical-chard.glitch.me', |
|
'https://sincere-rain-celsius.glitch.me', |
|
'https://thunder-certain-viscount.glitch.me', |
|
'https://slender-twisty-turnover.glitch.me', |
|
'https://fearless-dolomite-macrame.glitch.me', |
|
'https://invited-mysterious-puma.glitch.me', |
|
'https://coherent-concise-mallet.glitch.me', |
|
'https://waiting-obtainable-cloche.glitch.me', |
|
'https://volcano-pumped-flag.glitch.me', |
|
'https://burnt-six-cricket.glitch.me', |
|
'https://cerulean-jelly-sailfish.glitch.me', |
|
'https://crawling-thoughtful-bush.glitch.me', |
|
'https://leeward-citrine-snap.glitch.me', |
|
'https://capable-amenable-philosophy.glitch.me', |
|
'https://husky-curved-jobaria.glitch.me', |
|
'https://peppermint-rust-darkness.glitch.me', |
|
'https://shadow-spectacular-balaur.glitch.me', |
|
'https://chlorinated-lead-homburg.glitch.me', |
|
'https://victorious-sand-turn.glitch.me', |
|
'https://elegant-prong-tiara.glitch.me', |
|
'https://efficient-bold-nautilus.glitch.me', |
|
'https://tiny-crimson-seahorse.glitch.me', |
|
'https://nervous-indigo-song.glitch.me', |
|
'https://lavender-ember-zebra.glitch.me', |
|
'https://cherry-weak-beaufort.glitch.me', |
|
'https://lavish-rare-giganotosaurus.glitch.me', |
|
'https://extreme-butter-mind.glitch.me', |
|
'https://sage-road-cirrus.glitch.me', |
|
'https://surf-peppermint-gallon.glitch.me', |
|
'https://curvy-same-allium.glitch.me', |
|
'https://scythe-canyon-whale.glitch.me', |
|
'https://rose-funny-jasmine.glitch.me', |
|
'https://pinto-hill-nyala.glitch.me', |
|
'https://prairie-carnation-pincushion.glitch.me', |
|
'https://sticky-wobbly-bagpipe.glitch.me', |
|
'https://jolly-charmed-interest.glitch.me', |
|
'https://discovered-ajar-kilogram.glitch.me', |
|
|
|
|
|
|
|
|
|
|
|
'https://www.google.com' |
|
|
|
]; |
|
|
|
|
|
websites.forEach(async (url) => { |
|
try { |
|
const response = await axios.get(url); |
|
console.log(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Visited web successfully: ${url} - Status code: ${response.status}\n`); |
|
} catch (error) { |
|
console.error(`Error visiting ${url}: ${error.message}\n`); |
|
} |
|
}); |
|
} |
|
|
|
|
|
function checkAndSetTimer() { |
|
const currentMoment = moment().tz('Asia/Hong_Kong'); |
|
const formattedTime = currentMoment.format('YYYY-MM-DD HH:mm:ss'); |
|
if (currentMoment.hours() >= 1 && currentMoment.hours() < 5) { |
|
console.log(`Stop visit from 1:00 to 8:00 --- ${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')}`); |
|
clearInterval(visitIntervalId); |
|
const nextVisitTime = moment().tz('Asia/Hong_Kong').add(0, 'day').hours(8).minutes(0).seconds(0); |
|
const nextVisitInterval = nextVisitTime.diff(currentMoment); |
|
setTimeout(() => { |
|
startVisits(); |
|
}, nextVisitInterval); |
|
} else { |
|
startVisits(); |
|
} |
|
} |
|
|
|
let visitIntervalId; |
|
function startVisits() { |
|
clearInterval(visitIntervalId); |
|
|
|
visitIntervalId = setInterval(() => { |
|
visitWebsites(); |
|
}, 2 * 60 * 1000); |
|
} |
|
|
|
function runScript() { |
|
const runScriptIntervalId = setInterval(() => { |
|
|
|
checkAndSetTimer(); |
|
}, 2 * 60 * 1000); |
|
} |
|
checkAndSetTimer(); |
|
runScript(); |
|
|
|
|
|
async function scrapeAndLog(url) { |
|
try { |
|
const response = await axios.get(url); |
|
console.log(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')} Web visited Successfully: ${url} - Status code: ${response.status}\n`); |
|
} catch (error) { |
|
console.error(`${moment().tz('Asia/Hong_Kong').format('YYYY-MM-DD HH:mm:ss')}: Web visited Error: ${url}: ${error.message}\n`); |
|
} |
|
} |
|
|
|
cron.schedule('*/2 * * * *', () => { |
|
console.log('Running webpage access...'); |
|
urls.forEach((url) => { |
|
scrapeAndLog(url); |
|
}); |
|
}); |
|
|
|
|
|
const server = http.createServer((req, res) => { |
|
if (req.url === '/') { |
|
res.writeHead(200, {'Content-Type': 'text/plain'}); |
|
res.end('Hello, World!\n'); |
|
} else { |
|
res.writeHead(404, {'Content-Type': 'text/plain'}); |
|
res.end('Not Found\n'); |
|
} |
|
}); |
|
|
|
server.listen(port, () => { |
|
console.log(`Server is running on port:${port}`); |
|
}); |
|
|