Repository navigation
Expand file tree
/
Copy pathplay.js
More file actions
82 lines (63 loc) · 2.38 KB
/
Copy pathplay.js
File metadata and controls
82 lines (63 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const { chromium } = require('@playwright/test');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
// 获取今天日期 往后的8个小时
const today = dateFormat(new Date(), 'yyyy-MM-dd')
let mdContext = "## 每日prompt"+"\n"+"### "+today+"\n" + "<center class=\"half\">"
// 获取 apiKey 通过 https://arthub.ai/assets/index.684ec127.js
await page.goto('https://arthub.ai');
const entries = await page.$$('div.relative.card.mb-12.h-fit.transition-transform.svelte-j8kxlt');
for (let i = 0; i < entries.length; i++) {
// console.log('index entry:', i);
// Get the prompt text
const prompts = await entries[i].$$('.svelte-j8kxlt.svelte-j8kxlt > p');
if (prompts.length === 0) {
console.log('could not find prompts element');
continue;
}
let promptText = '';
for (const prompt of prompts) {
const text = await prompt.textContent();
promptText += text;
}
console.log('promptText:', promptText);
mdContext += `<p>${promptText}</p>\n`;
const imgs = await entries[i].$$('.relative.z-10.w-full.rounded-md > div > img');
if (imgs.length === 0) {
console.log('could not find img element');
continue;
}
for (const img of imgs) {
const src = await img.getAttribute('src');
console.log('src:', src);
mdContext += `<img src="${src}" width="200"/>\n`;
}
// 添加下划线
mdContext += '<hr>\n';
}
mdContext += '</center>';
console.log('mdContext:', mdContext);
// Write mdContext to file
const fs = require('fs');
fs.writeFileSync('README.md', mdContext, 'utf8');
await browser.close();
})();
function dateFormat (date, format) {
date = new Date(date);
var o = {
'M+' : date.getMonth() + 1, //month
'd+' : date.getDate(), //day
'H+' : date.getHours()+8, //hour+8小时
'm+' : date.getMinutes(), //minute
's+' : date.getSeconds(), //second
'q+' : Math.floor((date.getMonth() + 3) / 3), //quarter
'S' : date.getMilliseconds() //millisecond
};
if (/(y+)/.test(format))
format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp('(' + k + ')').test(format))
format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));
return format;
}