pin5719's picture
Update index.js
6f6aa03 verified
raw
history blame
7.38 kB
const axios = require('axios');
const http = require('http');
const cron = require('node-cron');
const port = process.env.PORT || 7860;
const moment = require('moment-timezone');
// 添加24小时访问的URL数组
const urls = [
'https://3007ab38-260a-4a94-8ac3-16dfe0138811-00-w9wh800nmf0j.pike.replit.dev', // 此处可备注名称,例如:H080
'https://www.yahoo.com', // 此处可备注名称,例如:glitch
'https://www.baidu.com', // 此处可备注名称,例如:glitch
'https://www.yahoo.com', // 此处可备注名称,例如:glitch
'https://www.baidu.com', // 此处可备注名称,例如:glitch
'https://www.yahoo.com', // 此处可备注名称,例如:glitch
'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', // 此处可备注名称,例如:glitch
'https://www.yahoo.com', // 此处可备注名称,例如:glitch
// 添加更多24小时不间断访问的URL
];
// 添加在01:00至05:00暂停访问,其他时间正常访问的URL数组
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' // 此处可备注名称,例如:Back4app,最后一个url后面没有逗号
//添加更多的指定时间访问的URL
];
// 遍历网页数组并发送请求
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);
// visitWebsites();
visitIntervalId = setInterval(() => {
visitWebsites();
}, 3 * 60 * 1000); // 每2分钟执行一次访问
}
function runScript() {
const runScriptIntervalId = setInterval(() => {
//console.log('Running script');
checkAndSetTimer();
}, 3 * 60 * 1000); // 每2分钟检查一次
}
checkAndSetTimer();
runScript();
// 24小时不间断访问
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`);
}
}
// 每3分钟访问一次
cron.schedule('*/2 * * * *', () => {
console.log('Running webpage access...');
urls.forEach((url) => {
scrapeAndLog(url);
});
});
// 创建HTTP服务
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}`);
});