|
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://3007ab38-260a-4a94-8ac3-16dfe0138811-00-w9wh800nmf0j.pike.replit.dev', |
|
'https://www.yahoo.com', |
|
'https://www.baidu.com', |
|
'https://www.yahoo.com', |
|
'https://www.baidu.com', |
|
'https://www.yahoo.com', |
|
|
|
'https://turquoise-blossom-fiction.glitch.me', |
|
'https://amber-grandiose-cartwheel.glitch.me', |
|
'https://aboard-inconclusive-jersey.glitch.me', |
|
'https://early-dusty-brand.glitch.me', |
|
'https://shrouded-tinted-tower.glitch.me', |
|
'https://marbled-oil-macadamia.glitch.me', |
|
'https://actually-little-end.glitch.me', |
|
'https://pickle-nebula-nephew.glitch.me', |
|
'https://everlasting-ripple-pie.glitch.me', |
|
'https://bumpy-pentagonal-lens.glitch.me', |
|
|
|
|
|
|
|
|
|
|
|
'https://www.baidu.com', |
|
'https://www.yahoo.com', |
|
|
|
]; |
|
|
|
|
|
function visitWebsites() { |
|
const websites = [ |
|
|
|
'https://gdd45c-3000.csb.app', |
|
|
|
'https://mud-roasted-relative.glitch.me', |
|
'https://omniscient-buttery-plate.glitch.me', |
|
'https://jade-planet-wasp.glitch.me', |
|
'https://fantasy-everlasting-hydrofoil.glitch.me', |
|
'https://disco-hungry-soda.glitch.me', |
|
'https://spiky-pyrite-sled.glitch.me', |
|
'https://awesome-proud-dogsled.glitch.me', |
|
'https://scrawny-fluorescent-pet.glitch.me', |
|
'https://rhinestone-road-foundation.glitch.me', |
|
'https://discovered-hot-cloud.glitch.me', |
|
'https://crimson-classy-spectroscope.glitch.me', |
|
'https://efficient-just-camelotia.glitch.me', |
|
'https://efficient-beaded-sternum.glitch.me', |
|
'https://hill-marmalade-promotion.glitch.me', |
|
'https://kindly-possible-chickadee.glitch.me', |
|
'https://powerful-boatneck-mice.glitch.me', |
|
'https://resolute-juvenile-hyena.glitch.me', |
|
'https://melodic-local-tadpole.glitch.me', |
|
'https://pear-absorbed-skate.glitch.me', |
|
'https://inconclusive-functional-message.glitch.me', |
|
'https://abstracted-giddy-gibbon.glitch.me', |
|
'https://foil-funky-hen.glitch.me', |
|
'https://equable-diligent-candle.glitch.me', |
|
'https://triangular-chocolate-hosta.glitch.me', |
|
'https://pretty-sixth-silene.glitch.me', |
|
'https://kindly-turquoise-hippopotamus.glitch.me', |
|
'https://hickory-motley-snowflake.glitch.me', |
|
'https://quill-tangible-longan.glitch.me', |
|
'https://second-phase-motorcycle.glitch.me', |
|
'https://steady-narrow-timimus.glitch.me', |
|
'https://inconclusive-carnelian-aardwolf.glitch.me', |
|
'https://rustic-equal-jasmine.glitch.me', |
|
'https://tortoiseshell-branch-twill.glitch.me', |
|
'https://showy-fish-tithonia.glitch.me', |
|
'https://bottlenose-spiky-teller.glitch.me', |
|
'https://winter-sturdy-persimmon.glitch.me', |
|
'https://peppered-ossified-candy.glitch.me', |
|
'https://paint-typical-coach.glitch.me', |
|
'https://battle-vanilla-reindeer.glitch.me', |
|
'https://terrific-decorous-trouser.glitch.me', |
|
'https://ancient-melodious-crayon.glitch.me', |
|
'https://intelligent-outrageous-wasabi.glitch.me', |
|
'https://catkin-turquoise-silverfish.glitch.me', |
|
'https://level-humane-rail.glitch.me', |
|
'https://gleaming-hot-condorraptor.glitch.me', |
|
'https://lunar-lydian-triangle.glitch.me', |
|
'https://rare-thirsty-coat.glitch.me', |
|
'https://imaginary-brainy-spoon.glitch.me', |
|
'https://fortunate-airy-hexagon.glitch.me', |
|
'https://groovy-rural-statistic.glitch.me', |
|
'https://chambray-obvious-bus.glitch.me', |
|
'https://platinum-lavish-prawn.glitch.me', |
|
'https://dust-liberating-fig.glitch.me', |
|
'https://pear-fluoridated-heaven.glitch.me', |
|
'https://complete-therapeutic-random.glitch.me', |
|
'https://acoustic-different-healer.glitch.me', |
|
'https://octagonal-heliotrope-event.glitch.me', |
|
'https://sugar-onyx-crane.glitch.me', |
|
'https://honeysuckle-wistful-pyramid.glitch.me', |
|
'https://few-lively-kettle.glitch.me', |
|
'https://volcano-full-salmon.glitch.me', |
|
'https://flaxen-steadfast-patella.glitch.me', |
|
'https://flash-aquatic-citipati.glitch.me', |
|
'https://florentine-swanky-taker.glitch.me', |
|
'https://unique-efficient-inch.glitch.me', |
|
'https://puddle-rare-observatory.glitch.me', |
|
'https://imported-golden-motion.glitch.me', |
|
'https://regal-responsible-yam.glitch.me', |
|
'https://sulky-sleepy-freesia.glitch.me', |
|
'https://fog-seed-bassoon.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 5: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(5).minutes(0).seconds(0); |
|
const nextVisitInterval = nextVisitTime.diff(currentMoment); |
|
setTimeout(() => { |
|
startVisits(); |
|
}, nextVisitInterval); |
|
} else { |
|
startVisits(); |
|
} |
|
} |
|
|
|
let visitIntervalId; |
|
function startVisits() { |
|
clearInterval(visitIntervalId); |
|
|
|
visitIntervalId = setInterval(() => { |
|
visitWebsites(); |
|
}, 3 * 60 * 1000); |
|
} |
|
|
|
function runScript() { |
|
const runScriptIntervalId = setInterval(() => { |
|
|
|
checkAndSetTimer(); |
|
}, 3 * 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}`); |
|
}); |
|
|