Spaces:
Running
Running
connorlixyz
commited on
Commit
•
ce5a60e
1
Parent(s):
3e9ecdb
Upload 4 files
Browse files- Dockerfile +12 -0
- index.html +66 -0
- index.js +76 -0
- package.json +21 -0
Dockerfile
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM node:slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY . .
|
6 |
+
|
7 |
+
EXPOSE 7860
|
8 |
+
|
9 |
+
RUN apt update -y &&\
|
10 |
+
npm install
|
11 |
+
|
12 |
+
CMD ["node", "index.js"]
|
index.html
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<title>蜀 道 难</title>
|
6 |
+
<style>
|
7 |
+
body {
|
8 |
+
font-family: Arial, sans-serif;
|
9 |
+
text-align: center;
|
10 |
+
background-color: #f0f0f0;
|
11 |
+
}
|
12 |
+
header {
|
13 |
+
background-color: #4a4a4a;
|
14 |
+
color: #fff;
|
15 |
+
padding: 2px;
|
16 |
+
}
|
17 |
+
h1 {
|
18 |
+
font-size: 36px;
|
19 |
+
}
|
20 |
+
#content {
|
21 |
+
max-width: 800px;
|
22 |
+
margin: 0 auto;
|
23 |
+
padding: 20px;
|
24 |
+
background-color: #fff;
|
25 |
+
border-radius: 5px;
|
26 |
+
}
|
27 |
+
p {
|
28 |
+
font-size: 18px;
|
29 |
+
line-height: 1.5;
|
30 |
+
}
|
31 |
+
</style>
|
32 |
+
</head>
|
33 |
+
<body>
|
34 |
+
<header>
|
35 |
+
<h1>蜀道难</h1>
|
36 |
+
</header>
|
37 |
+
<div id="content">
|
38 |
+
<p>噫吁嚱,危乎高哉!</p>
|
39 |
+
<p>蜀道之难,难于上青天!</p>
|
40 |
+
<p>蚕丛及鱼凫,开国何茫然!</p>
|
41 |
+
<p>尔来四万八千岁,不与秦塞通人烟。</p>
|
42 |
+
<p>西当太白有鸟道,可以横绝峨眉巅。</p>
|
43 |
+
<p>地崩山摧壮士死,然后天梯石栈相钩连。</p>
|
44 |
+
<p>上有六龙回日之高标,下有冲波逆折之回川。</p>
|
45 |
+
<p>黄鹤之飞尚不得过,猿猱欲度愁攀援。</p>
|
46 |
+
<p>青泥何盘盘,百步九折萦岩峦。</p>
|
47 |
+
<p>扪参历井仰胁息,以手抚膺坐长叹。</p>
|
48 |
+
<br></br>
|
49 |
+
<p>问君西游何时还?畏途巉岩不可攀。</p>
|
50 |
+
<p>但见悲鸟号古木,雄飞雌从绕林间。</p>
|
51 |
+
<p>又闻子规啼夜月,愁空山。</p>
|
52 |
+
<p>蜀道之难,难于上青天,使人听此凋朱颜!</p>
|
53 |
+
<p>连峰去天不盈尺,枯松倒挂倚绝壁。</p>
|
54 |
+
<p>飞湍瀑流争喧豗,砯崖转石万壑雷。</p>
|
55 |
+
<p>其险也如此,嗟尔远道之人胡为乎来哉!(也如此 一作:也若此)</p>
|
56 |
+
<br></br>
|
57 |
+
<p>剑阁峥嵘而崔嵬,一夫当关,万夫莫开。</p>
|
58 |
+
<p>所守或匪亲,化为狼与豺。</p>
|
59 |
+
<p>朝避猛虎,夕避长蛇,磨牙吮血,杀人如麻。</p>
|
60 |
+
<p>锦城虽云乐,不如早还家。</p>
|
61 |
+
<p>蜀道之难,难于上青天,侧身西望长咨嗟!</p>
|
62 |
+
|
63 |
+
|
64 |
+
</div>
|
65 |
+
</body>
|
66 |
+
</html>
|
index.js
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const axios = require('axios');
|
2 |
+
const fs = require('fs');
|
3 |
+
const cron = require('node-cron');
|
4 |
+
const http = require('http');
|
5 |
+
const path = require('path');
|
6 |
+
const port = process.env.PORT || 7860;
|
7 |
+
|
8 |
+
// 定义要访问的网页URL数组
|
9 |
+
const urls = [
|
10 |
+
//huggingface
|
11 |
+
'https://connorlixyz-autoliveformcst.hf.space', // huggingface-本项目
|
12 |
+
//Goorm
|
13 |
+
'https://my-nodejs-ivzud.run-us-west2.goorm.site', // Goorm-linshi
|
14 |
+
'https://ide-run.goorm.io/workspace/d8MS7D1BaRxuHgRKnSW?token=ada5536dbe5768f245c935ab547af078&guestname=0123', // MC-servers-py
|
15 |
+
|
16 |
+
|
17 |
+
// 添加更多的URL
|
18 |
+
];
|
19 |
+
|
20 |
+
// 创建日志文件
|
21 |
+
//const logFile = 'visit-log.txt';
|
22 |
+
|
23 |
+
// 访问网页并将结果写入日志
|
24 |
+
async function scrapeAndLog(url) {
|
25 |
+
try {
|
26 |
+
const response = await axios.get(url, {timeout: 1000});
|
27 |
+
const timestamp = new Date().toISOString();
|
28 |
+
const logMessage = `${timestamp}: Web visited Successfully ${url}\n`;
|
29 |
+
|
30 |
+
// 将访问结果写入日志文件
|
31 |
+
// fs.appendFileSync(logFile, logMessage);
|
32 |
+
|
33 |
+
console.log(logMessage);
|
34 |
+
} catch (error) {
|
35 |
+
const timestamp = new Date().toISOString();
|
36 |
+
const errorMessage = `${timestamp}: Web visited Error ${url}: ${error.message}\n`;
|
37 |
+
|
38 |
+
// 将错误信息写入日志文件
|
39 |
+
// fs.appendFileSync(logFile, errorMessage);
|
40 |
+
|
41 |
+
console.error(errorMessage);
|
42 |
+
}
|
43 |
+
}
|
44 |
+
|
45 |
+
// 使用cron来安排定期任务
|
46 |
+
cron.schedule('0 */2 * * * *', () => {
|
47 |
+
console.log('Running webpage access...');
|
48 |
+
// 循环访问每个URL
|
49 |
+
urls.forEach((url) => {
|
50 |
+
scrapeAndLog(url);
|
51 |
+
});
|
52 |
+
});
|
53 |
+
|
54 |
+
|
55 |
+
const server = http.createServer((req, res) => {
|
56 |
+
if (req.url === '/') {
|
57 |
+
const filePath = path.join(__dirname, 'index.html');
|
58 |
+
|
59 |
+
fs.readFile(filePath, (err, data) => {
|
60 |
+
if (err) {
|
61 |
+
res.writeHead(500);
|
62 |
+
res.end('Error loading index.html');
|
63 |
+
} else {
|
64 |
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
65 |
+
res.end(data);
|
66 |
+
}
|
67 |
+
});
|
68 |
+
} else {
|
69 |
+
res.writeHead(404);
|
70 |
+
res.end('Not Found');
|
71 |
+
}
|
72 |
+
});
|
73 |
+
|
74 |
+
server.listen(port, () => {
|
75 |
+
console.log(`Server is running on port ${port}`);
|
76 |
+
});
|
package.json
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "auto-keep",
|
3 |
+
"version": "1.0.0",
|
4 |
+
"description": "auto-keep",
|
5 |
+
"main": "index.js",
|
6 |
+
"author": "okka",
|
7 |
+
"license": "MIT",
|
8 |
+
"private": false,
|
9 |
+
"scripts": {
|
10 |
+
"start": "node index.js"
|
11 |
+
},
|
12 |
+
"dependencies": {
|
13 |
+
"express": "^4.18.2",
|
14 |
+
"request": "^2.88.2",
|
15 |
+
"axios": "^1.5.0",
|
16 |
+
"node-cron": "^2.0.1"
|
17 |
+
},
|
18 |
+
"engines": {
|
19 |
+
"node": ">=14"
|
20 |
+
}
|
21 |
+
}
|