@jackwener/opencli 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLI-CREATOR.md +51 -72
- package/README.md +8 -5
- package/README.zh-CN.md +8 -5
- package/SKILL.md +27 -14
- package/dist/browser.d.ts +6 -0
- package/dist/browser.js +65 -1
- package/dist/clis/bilibili/dynamic.d.ts +1 -0
- package/dist/clis/bilibili/dynamic.js +33 -0
- package/dist/clis/bilibili/ranking.d.ts +1 -0
- package/dist/clis/bilibili/ranking.js +24 -0
- package/dist/clis/reddit/frontpage.yaml +30 -0
- package/dist/clis/reddit/hot.yaml +3 -2
- package/dist/clis/reddit/search.yaml +34 -0
- package/dist/clis/reddit/subreddit.yaml +39 -0
- package/dist/clis/twitter/bookmarks.yaml +85 -0
- package/dist/clis/twitter/profile.d.ts +1 -0
- package/dist/clis/twitter/profile.js +56 -0
- package/dist/clis/twitter/search.d.ts +1 -0
- package/dist/clis/twitter/search.js +60 -0
- package/dist/clis/twitter/timeline.d.ts +1 -0
- package/dist/clis/twitter/timeline.js +47 -0
- package/dist/clis/xiaohongshu/user.d.ts +1 -0
- package/dist/clis/xiaohongshu/user.js +40 -0
- package/dist/clis/xueqiu/feed.yaml +53 -0
- package/dist/clis/xueqiu/hot-stock.yaml +49 -0
- package/dist/clis/xueqiu/hot.yaml +46 -0
- package/dist/clis/xueqiu/search.yaml +53 -0
- package/dist/clis/xueqiu/stock.yaml +67 -0
- package/dist/clis/xueqiu/watchlist.yaml +46 -0
- package/dist/clis/zhihu/hot.yaml +6 -2
- package/dist/clis/zhihu/search.yaml +3 -1
- package/dist/engine.d.ts +1 -1
- package/dist/engine.js +9 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.js +10 -3
- package/dist/pipeline/steps/intercept.js +56 -29
- package/dist/pipeline/template.js +3 -1
- package/dist/pipeline/template.test.js +6 -0
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
- package/src/browser.ts +72 -4
- package/src/clis/bilibili/dynamic.ts +34 -0
- package/src/clis/bilibili/ranking.ts +25 -0
- package/src/clis/reddit/frontpage.yaml +30 -0
- package/src/clis/reddit/hot.yaml +3 -2
- package/src/clis/reddit/search.yaml +34 -0
- package/src/clis/reddit/subreddit.yaml +39 -0
- package/src/clis/twitter/bookmarks.yaml +85 -0
- package/src/clis/twitter/profile.ts +61 -0
- package/src/clis/twitter/search.ts +65 -0
- package/src/clis/twitter/timeline.ts +50 -0
- package/src/clis/xiaohongshu/user.ts +45 -0
- package/src/clis/xueqiu/feed.yaml +53 -0
- package/src/clis/xueqiu/hot-stock.yaml +49 -0
- package/src/clis/xueqiu/hot.yaml +46 -0
- package/src/clis/xueqiu/search.yaml +53 -0
- package/src/clis/xueqiu/stock.yaml +67 -0
- package/src/clis/xueqiu/watchlist.yaml +46 -0
- package/src/clis/zhihu/hot.yaml +6 -2
- package/src/clis/zhihu/search.yaml +3 -1
- package/src/engine.ts +10 -1
- package/src/main.ts +9 -3
- package/src/pipeline/steps/intercept.ts +58 -28
- package/src/pipeline/template.test.ts +6 -0
- package/src/pipeline/template.ts +3 -1
- package/src/types.ts +3 -0
- package/dist/clis/index.d.ts +0 -22
- package/dist/clis/index.js +0 -34
- package/src/clis/index.ts +0 -46
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
site: twitter
|
|
2
|
+
name: bookmarks
|
|
3
|
+
description: 获取 Twitter 书签列表
|
|
4
|
+
domain: x.com
|
|
5
|
+
browser: true
|
|
6
|
+
|
|
7
|
+
args:
|
|
8
|
+
limit:
|
|
9
|
+
type: int
|
|
10
|
+
default: 20
|
|
11
|
+
description: Number of bookmarks to return (default 20)
|
|
12
|
+
|
|
13
|
+
pipeline:
|
|
14
|
+
- navigate: https://x.com/i/bookmarks
|
|
15
|
+
- wait: 2
|
|
16
|
+
- evaluate: |
|
|
17
|
+
(async () => {
|
|
18
|
+
const ct0 = document.cookie.split(';').map(c=>c.trim()).find(c=>c.startsWith('ct0='))?.split('=')[1];
|
|
19
|
+
if (!ct0) throw new Error('No ct0 cookie. Hint: Not logged into x.com.');
|
|
20
|
+
const bearer = decodeURIComponent('AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA');
|
|
21
|
+
const _h = {'Authorization':'Bearer '+bearer, 'X-Csrf-Token':ct0, 'X-Twitter-Auth-Type':'OAuth2Session', 'X-Twitter-Active-User':'yes'};
|
|
22
|
+
|
|
23
|
+
const count = Math.min(${{ args.limit }}, 100);
|
|
24
|
+
const variables = JSON.stringify({count, includePromotedContent: false});
|
|
25
|
+
const features = JSON.stringify({
|
|
26
|
+
rweb_video_screen_enabled: false, profile_label_improvements_pcf_label_in_post_enabled: true,
|
|
27
|
+
responsive_web_profile_redirect_enabled: false, rweb_tipjar_consumption_enabled: false,
|
|
28
|
+
verified_phone_label_enabled: false, creator_subscriptions_tweet_preview_api_enabled: true,
|
|
29
|
+
responsive_web_graphql_timeline_navigation_enabled: true,
|
|
30
|
+
responsive_web_graphql_skip_user_profile_image_extensions_enabled: false,
|
|
31
|
+
premium_content_api_read_enabled: false, communities_web_enable_tweet_community_results_fetch: true,
|
|
32
|
+
c9s_tweet_anatomy_moderator_badge_enabled: true,
|
|
33
|
+
articles_preview_enabled: true, responsive_web_edit_tweet_api_enabled: true,
|
|
34
|
+
graphql_is_translatable_rweb_tweet_is_translatable_enabled: true,
|
|
35
|
+
view_counts_everywhere_api_enabled: true, longform_notetweets_consumption_enabled: true,
|
|
36
|
+
responsive_web_twitter_article_tweet_consumption_enabled: true,
|
|
37
|
+
tweet_awards_web_tipping_enabled: false,
|
|
38
|
+
content_disclosure_indicator_enabled: true, content_disclosure_ai_generated_indicator_enabled: true,
|
|
39
|
+
freedom_of_speech_not_reach_fetch_enabled: true, standardized_nudges_misinfo: true,
|
|
40
|
+
tweet_with_visibility_results_prefer_gql_limited_actions_policy_enabled: true,
|
|
41
|
+
longform_notetweets_rich_text_read_enabled: true, longform_notetweets_inline_media_enabled: false,
|
|
42
|
+
responsive_web_enhance_cards_enabled: false
|
|
43
|
+
});
|
|
44
|
+
const url = '/i/api/graphql/Fy0QMy4q_aZCpkO0PnyLYw/Bookmarks?variables=' + encodeURIComponent(variables) + '&features=' + encodeURIComponent(features);
|
|
45
|
+
const resp = await fetch(url, {headers: _h, credentials: 'include'});
|
|
46
|
+
if (!resp.ok) throw new Error('HTTP ' + resp.status + '. Hint: queryId may have changed.');
|
|
47
|
+
const d = await resp.json();
|
|
48
|
+
|
|
49
|
+
const instructions = d.data?.bookmark_timeline_v2?.timeline?.instructions || d.data?.bookmark_timeline?.timeline?.instructions || [];
|
|
50
|
+
let tweets = [], seen = new Set();
|
|
51
|
+
for (const inst of instructions) {
|
|
52
|
+
for (const entry of (inst.entries || [])) {
|
|
53
|
+
const r = entry.content?.itemContent?.tweet_results?.result;
|
|
54
|
+
if (!r) continue;
|
|
55
|
+
const tw = r.tweet || r;
|
|
56
|
+
const l = tw.legacy || {};
|
|
57
|
+
if (!tw.rest_id || seen.has(tw.rest_id)) continue;
|
|
58
|
+
seen.add(tw.rest_id);
|
|
59
|
+
const u = tw.core?.user_results?.result;
|
|
60
|
+
const nt = tw.note_tweet?.note_tweet_results?.result?.text;
|
|
61
|
+
const screenName = u?.legacy?.screen_name || u?.core?.screen_name;
|
|
62
|
+
tweets.push({
|
|
63
|
+
id: tw.rest_id,
|
|
64
|
+
author: screenName,
|
|
65
|
+
name: u?.legacy?.name || u?.core?.name,
|
|
66
|
+
url: 'https://x.com/' + (screenName || '_') + '/status/' + tw.rest_id,
|
|
67
|
+
text: nt || l.full_text || '',
|
|
68
|
+
likes: l.favorite_count,
|
|
69
|
+
retweets: l.retweet_count,
|
|
70
|
+
created_at: l.created_at
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return tweets;
|
|
75
|
+
})()
|
|
76
|
+
|
|
77
|
+
- map:
|
|
78
|
+
author: ${{ item.author }}
|
|
79
|
+
text: ${{ item.text }}
|
|
80
|
+
likes: ${{ item.likes }}
|
|
81
|
+
url: ${{ item.url }}
|
|
82
|
+
|
|
83
|
+
- limit: ${{ args.limit }}
|
|
84
|
+
|
|
85
|
+
columns: [author, text, likes, url]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
cli({
|
|
3
|
+
site: 'twitter',
|
|
4
|
+
name: 'profile',
|
|
5
|
+
description: 'Fetch tweets from a user profile',
|
|
6
|
+
domain: 'x.com',
|
|
7
|
+
strategy: Strategy.INTERCEPT,
|
|
8
|
+
browser: true,
|
|
9
|
+
args: [
|
|
10
|
+
{ name: 'username', type: 'string', required: true },
|
|
11
|
+
{ name: 'limit', type: 'int', default: 15 },
|
|
12
|
+
],
|
|
13
|
+
columns: ['id', 'text', 'likes', 'views', 'url'],
|
|
14
|
+
func: async (page, kwargs) => {
|
|
15
|
+
// Navigate to user profile via search for reliability
|
|
16
|
+
await page.goto(`https://x.com/search?q=from:${kwargs.username}&f=live`);
|
|
17
|
+
await page.wait(5);
|
|
18
|
+
// Inject XHR interceptor
|
|
19
|
+
await page.installInterceptor('SearchTimeline');
|
|
20
|
+
// Trigger API by scrolling
|
|
21
|
+
await page.autoScroll({ times: 3, delayMs: 2000 });
|
|
22
|
+
// Retrieve data
|
|
23
|
+
const requests = await page.getInterceptedRequests();
|
|
24
|
+
if (!requests || requests.length === 0)
|
|
25
|
+
return [];
|
|
26
|
+
let results = [];
|
|
27
|
+
for (const req of requests) {
|
|
28
|
+
try {
|
|
29
|
+
const insts = req.data.data.search_by_raw_query.search_timeline.timeline.instructions;
|
|
30
|
+
const addEntries = insts.find((i) => i.type === 'TimelineAddEntries');
|
|
31
|
+
if (!addEntries)
|
|
32
|
+
continue;
|
|
33
|
+
for (const entry of addEntries.entries) {
|
|
34
|
+
if (!entry.entryId.startsWith('tweet-'))
|
|
35
|
+
continue;
|
|
36
|
+
let tweet = entry.content?.itemContent?.tweet_results?.result;
|
|
37
|
+
if (!tweet)
|
|
38
|
+
continue;
|
|
39
|
+
if (tweet.__typename === 'TweetWithVisibilityResults' && tweet.tweet) {
|
|
40
|
+
tweet = tweet.tweet;
|
|
41
|
+
}
|
|
42
|
+
results.push({
|
|
43
|
+
id: tweet.rest_id,
|
|
44
|
+
text: tweet.legacy?.full_text || '',
|
|
45
|
+
likes: tweet.legacy?.favorite_count || 0,
|
|
46
|
+
views: tweet.views?.count || '0',
|
|
47
|
+
url: `https://x.com/i/status/${tweet.rest_id}`
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return results.slice(0, kwargs.limit);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
cli({
|
|
3
|
+
site: 'twitter',
|
|
4
|
+
name: 'search',
|
|
5
|
+
description: 'Search Twitter/X for tweets',
|
|
6
|
+
domain: 'x.com',
|
|
7
|
+
strategy: Strategy.INTERCEPT, // Use intercept strategy
|
|
8
|
+
browser: true,
|
|
9
|
+
args: [
|
|
10
|
+
{ name: 'query', type: 'string', required: true },
|
|
11
|
+
{ name: 'limit', type: 'int', default: 15 },
|
|
12
|
+
],
|
|
13
|
+
columns: ['id', 'author', 'text', 'likes', 'views', 'url'],
|
|
14
|
+
func: async (page, kwargs) => {
|
|
15
|
+
// 1. Navigate to the search page
|
|
16
|
+
const q = encodeURIComponent(kwargs.query);
|
|
17
|
+
await page.goto(`https://x.com/search?q=${q}&f=top`);
|
|
18
|
+
await page.wait(5);
|
|
19
|
+
// 2. Inject XHR interceptor
|
|
20
|
+
await page.installInterceptor('SearchTimeline');
|
|
21
|
+
// 3. Trigger API by scrolling
|
|
22
|
+
await page.autoScroll({ times: 3, delayMs: 2000 });
|
|
23
|
+
// 4. Retrieve data
|
|
24
|
+
const requests = await page.getInterceptedRequests();
|
|
25
|
+
if (!requests || requests.length === 0)
|
|
26
|
+
return [];
|
|
27
|
+
let results = [];
|
|
28
|
+
for (const req of requests) {
|
|
29
|
+
try {
|
|
30
|
+
const insts = req.data.data.search_by_raw_query.search_timeline.timeline.instructions;
|
|
31
|
+
const addEntries = insts.find((i) => i.type === 'TimelineAddEntries');
|
|
32
|
+
if (!addEntries)
|
|
33
|
+
continue;
|
|
34
|
+
for (const entry of addEntries.entries) {
|
|
35
|
+
if (!entry.entryId.startsWith('tweet-'))
|
|
36
|
+
continue;
|
|
37
|
+
let tweet = entry.content?.itemContent?.tweet_results?.result;
|
|
38
|
+
if (!tweet)
|
|
39
|
+
continue;
|
|
40
|
+
// Handle retweet wrapping
|
|
41
|
+
if (tweet.__typename === 'TweetWithVisibilityResults' && tweet.tweet) {
|
|
42
|
+
tweet = tweet.tweet;
|
|
43
|
+
}
|
|
44
|
+
results.push({
|
|
45
|
+
id: tweet.rest_id,
|
|
46
|
+
author: tweet.core?.user_results?.result?.legacy?.screen_name || 'unknown',
|
|
47
|
+
text: tweet.legacy?.full_text || '',
|
|
48
|
+
likes: tweet.legacy?.favorite_count || 0,
|
|
49
|
+
views: tweet.views?.count || '0',
|
|
50
|
+
url: `https://x.com/i/status/${tweet.rest_id}`
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
// ignore parsing errors for individual payloads
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return results.slice(0, kwargs.limit);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
cli({
|
|
3
|
+
site: 'twitter',
|
|
4
|
+
name: 'timeline',
|
|
5
|
+
description: 'Twitter Home Timeline',
|
|
6
|
+
domain: 'x.com',
|
|
7
|
+
strategy: Strategy.COOKIE,
|
|
8
|
+
args: [
|
|
9
|
+
{ name: 'limit', type: 'int', default: 20 },
|
|
10
|
+
],
|
|
11
|
+
columns: ['responseType', 'first'],
|
|
12
|
+
func: async (page, kwargs) => {
|
|
13
|
+
await page.goto('https://x.com/home');
|
|
14
|
+
await page.wait(5);
|
|
15
|
+
// Inject the fetch interceptor manually to see exactly what happens
|
|
16
|
+
await page.evaluate(`
|
|
17
|
+
() => {
|
|
18
|
+
window.__intercept_data = [];
|
|
19
|
+
const origFetch = window.fetch;
|
|
20
|
+
window.fetch = async function(...args) {
|
|
21
|
+
let u = typeof args[0] === 'string' ? args[0] : (args[0] && args[0].url) || '';
|
|
22
|
+
const res = await origFetch.apply(this, args);
|
|
23
|
+
setTimeout(async () => {
|
|
24
|
+
try {
|
|
25
|
+
if (u.includes('HomeTimeline')) {
|
|
26
|
+
const clone = res.clone();
|
|
27
|
+
const j = await clone.json();
|
|
28
|
+
window.__intercept_data.push(j);
|
|
29
|
+
}
|
|
30
|
+
} catch(e) {}
|
|
31
|
+
}, 0);
|
|
32
|
+
return res;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
`);
|
|
36
|
+
// trigger scroll
|
|
37
|
+
for (let i = 0; i < 3; i++) {
|
|
38
|
+
await page.evaluate('() => window.scrollTo(0, document.body.scrollHeight)');
|
|
39
|
+
await page.wait(2);
|
|
40
|
+
}
|
|
41
|
+
// extract
|
|
42
|
+
const data = await page.evaluate('() => window.__intercept_data');
|
|
43
|
+
if (!data || data.length === 0)
|
|
44
|
+
return [{ responseType: 'no data captured' }];
|
|
45
|
+
return [{ responseType: `captured ${data.length} responses`, first: JSON.stringify(data[0]).substring(0, 300) }];
|
|
46
|
+
}
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { cli, Strategy } from '../../registry.js';
|
|
2
|
+
cli({
|
|
3
|
+
site: 'xiaohongshu',
|
|
4
|
+
name: 'user',
|
|
5
|
+
description: 'Get user notes from Xiaohongshu',
|
|
6
|
+
domain: 'xiaohongshu.com',
|
|
7
|
+
strategy: Strategy.INTERCEPT,
|
|
8
|
+
browser: true,
|
|
9
|
+
args: [
|
|
10
|
+
{ name: 'id', type: 'string', required: true },
|
|
11
|
+
{ name: 'limit', type: 'int', default: 15 },
|
|
12
|
+
],
|
|
13
|
+
columns: ['id', 'title', 'type', 'likes', 'url'],
|
|
14
|
+
func: async (page, kwargs) => {
|
|
15
|
+
await page.goto(`https://www.xiaohongshu.com/user/profile/${kwargs.id}`);
|
|
16
|
+
await page.wait(5);
|
|
17
|
+
await page.installInterceptor('v1/user/posted');
|
|
18
|
+
// Trigger API by scrolling
|
|
19
|
+
await page.autoScroll({ times: 2, delayMs: 2000 });
|
|
20
|
+
// Retrieve data
|
|
21
|
+
const requests = await page.getInterceptedRequests();
|
|
22
|
+
if (!requests || requests.length === 0)
|
|
23
|
+
return [];
|
|
24
|
+
let results = [];
|
|
25
|
+
for (const req of requests) {
|
|
26
|
+
if (req.data && req.data.data && req.data.data.notes) {
|
|
27
|
+
for (const note of req.data.data.notes) {
|
|
28
|
+
results.push({
|
|
29
|
+
id: note.note_id || note.id,
|
|
30
|
+
title: note.display_title || '',
|
|
31
|
+
type: note.type || '',
|
|
32
|
+
likes: note.interact_info?.liked_count || '0',
|
|
33
|
+
url: `https://www.xiaohongshu.com/explore/${note.note_id || note.id}`
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return results.slice(0, kwargs.limit);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
site: xueqiu
|
|
2
|
+
name: feed
|
|
3
|
+
description: 获取雪球首页时间线(关注用户的动态)
|
|
4
|
+
domain: xueqiu.com
|
|
5
|
+
browser: true
|
|
6
|
+
|
|
7
|
+
args:
|
|
8
|
+
page:
|
|
9
|
+
type: int
|
|
10
|
+
default: 1
|
|
11
|
+
description: 页码,默认 1
|
|
12
|
+
limit:
|
|
13
|
+
type: int
|
|
14
|
+
default: 20
|
|
15
|
+
description: 每页数量,默认 20
|
|
16
|
+
|
|
17
|
+
pipeline:
|
|
18
|
+
- navigate: https://xueqiu.com
|
|
19
|
+
- evaluate: |
|
|
20
|
+
(async () => {
|
|
21
|
+
const page = ${{ args.page }};
|
|
22
|
+
const count = ${{ args.limit }};
|
|
23
|
+
const resp = await fetch(`https://xueqiu.com/v4/statuses/home_timeline.json?page=${page}&count=${count}`, {credentials: 'include'});
|
|
24
|
+
if (!resp.ok) throw new Error('HTTP ' + resp.status + ' Hint: Not logged in?');
|
|
25
|
+
const d = await resp.json();
|
|
26
|
+
|
|
27
|
+
const strip = (html) => (html || '').replace(/<[^>]+>/g, '').replace(/ /g, ' ').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').trim();
|
|
28
|
+
const list = d.home_timeline || d.list || [];
|
|
29
|
+
return list.map(item => {
|
|
30
|
+
const user = item.user || {};
|
|
31
|
+
return {
|
|
32
|
+
id: item.id,
|
|
33
|
+
text: strip(item.description).substring(0, 200),
|
|
34
|
+
url: 'https://xueqiu.com/' + user.id + '/' + item.id,
|
|
35
|
+
author: user.screen_name,
|
|
36
|
+
likes: item.fav_count,
|
|
37
|
+
retweets: item.retweet_count,
|
|
38
|
+
replies: item.reply_count,
|
|
39
|
+
created_at: item.created_at ? new Date(item.created_at).toISOString() : null
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
})()
|
|
43
|
+
|
|
44
|
+
- map:
|
|
45
|
+
author: ${{ item.author }}
|
|
46
|
+
text: ${{ item.text }}
|
|
47
|
+
likes: ${{ item.likes }}
|
|
48
|
+
replies: ${{ item.replies }}
|
|
49
|
+
url: ${{ item.url }}
|
|
50
|
+
|
|
51
|
+
- limit: ${{ args.limit }}
|
|
52
|
+
|
|
53
|
+
columns: [author, text, likes, replies, url]
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
site: xueqiu
|
|
2
|
+
name: hot-stock
|
|
3
|
+
description: 获取雪球热门股票榜
|
|
4
|
+
domain: xueqiu.com
|
|
5
|
+
browser: true
|
|
6
|
+
|
|
7
|
+
args:
|
|
8
|
+
limit:
|
|
9
|
+
type: int
|
|
10
|
+
default: 20
|
|
11
|
+
description: 返回数量,默认 20,最大 50
|
|
12
|
+
type:
|
|
13
|
+
type: str
|
|
14
|
+
default: "10"
|
|
15
|
+
description: 榜单类型 10=人气榜(默认) 12=关注榜
|
|
16
|
+
|
|
17
|
+
pipeline:
|
|
18
|
+
- navigate: https://xueqiu.com
|
|
19
|
+
- evaluate: |
|
|
20
|
+
(async () => {
|
|
21
|
+
const count = ${{ args.limit }};
|
|
22
|
+
const type = ${{ args.type | json }};
|
|
23
|
+
const resp = await fetch(`https://stock.xueqiu.com/v5/stock/hot_stock/list.json?size=${count}&type=${type}`, {credentials: 'include'});
|
|
24
|
+
if (!resp.ok) throw new Error('HTTP ' + resp.status + ' Hint: Not logged in?');
|
|
25
|
+
const d = await resp.json();
|
|
26
|
+
if (!d.data || !d.data.items) throw new Error('获取失败');
|
|
27
|
+
return d.data.items.map((s, i) => ({
|
|
28
|
+
rank: i + 1,
|
|
29
|
+
symbol: s.symbol,
|
|
30
|
+
name: s.name,
|
|
31
|
+
price: s.current,
|
|
32
|
+
changePercent: s.percent != null ? s.percent.toFixed(2) + '%' : null,
|
|
33
|
+
heat: s.value,
|
|
34
|
+
rank_change: s.rank_change,
|
|
35
|
+
url: 'https://xueqiu.com/S/' + s.symbol
|
|
36
|
+
}));
|
|
37
|
+
})()
|
|
38
|
+
|
|
39
|
+
- map:
|
|
40
|
+
rank: ${{ item.rank }}
|
|
41
|
+
symbol: ${{ item.symbol }}
|
|
42
|
+
name: ${{ item.name }}
|
|
43
|
+
price: ${{ item.price }}
|
|
44
|
+
changePercent: ${{ item.changePercent }}
|
|
45
|
+
heat: ${{ item.heat }}
|
|
46
|
+
|
|
47
|
+
- limit: ${{ args.limit }}
|
|
48
|
+
|
|
49
|
+
columns: [rank, symbol, name, price, changePercent, heat]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
site: xueqiu
|
|
2
|
+
name: hot
|
|
3
|
+
description: 获取雪球热门动态
|
|
4
|
+
domain: xueqiu.com
|
|
5
|
+
browser: true
|
|
6
|
+
|
|
7
|
+
args:
|
|
8
|
+
limit:
|
|
9
|
+
type: int
|
|
10
|
+
default: 20
|
|
11
|
+
description: 返回数量,默认 20,最大 50
|
|
12
|
+
|
|
13
|
+
pipeline:
|
|
14
|
+
- navigate: https://xueqiu.com
|
|
15
|
+
- evaluate: |
|
|
16
|
+
(async () => {
|
|
17
|
+
const resp = await fetch('https://xueqiu.com/statuses/hot/listV3.json?source=hot&page=1', {credentials: 'include'});
|
|
18
|
+
if (!resp.ok) throw new Error('HTTP ' + resp.status + ' Hint: Not logged in?');
|
|
19
|
+
const d = await resp.json();
|
|
20
|
+
const list = d.list || [];
|
|
21
|
+
|
|
22
|
+
const strip = (html) => (html || '').replace(/<[^>]+>/g, '').replace(/ /g, ' ').replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').trim();
|
|
23
|
+
return list.map((item, i) => {
|
|
24
|
+
const user = item.user || {};
|
|
25
|
+
return {
|
|
26
|
+
rank: i + 1,
|
|
27
|
+
text: strip(item.description).substring(0, 200),
|
|
28
|
+
url: 'https://xueqiu.com/' + user.id + '/' + item.id,
|
|
29
|
+
author: user.screen_name,
|
|
30
|
+
likes: item.fav_count,
|
|
31
|
+
retweets: item.retweet_count,
|
|
32
|
+
replies: item.reply_count
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
})()
|
|
36
|
+
|
|
37
|
+
- map:
|
|
38
|
+
rank: ${{ item.rank }}
|
|
39
|
+
author: ${{ item.author }}
|
|
40
|
+
text: ${{ item.text }}
|
|
41
|
+
likes: ${{ item.likes }}
|
|
42
|
+
url: ${{ item.url }}
|
|
43
|
+
|
|
44
|
+
- limit: ${{ args.limit }}
|
|
45
|
+
|
|
46
|
+
columns: [rank, author, text, likes, url]
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
site: xueqiu
|
|
2
|
+
name: search
|
|
3
|
+
description: 搜索雪球股票(代码或名称)
|
|
4
|
+
domain: xueqiu.com
|
|
5
|
+
browser: true
|
|
6
|
+
|
|
7
|
+
args:
|
|
8
|
+
query:
|
|
9
|
+
type: str
|
|
10
|
+
description: 搜索关键词,如 茅台、AAPL、腾讯
|
|
11
|
+
limit:
|
|
12
|
+
type: int
|
|
13
|
+
default: 10
|
|
14
|
+
description: 返回数量,默认 10
|
|
15
|
+
|
|
16
|
+
pipeline:
|
|
17
|
+
- navigate: https://xueqiu.com
|
|
18
|
+
- evaluate: |
|
|
19
|
+
(async () => {
|
|
20
|
+
const query = ${{ args.query | json }};
|
|
21
|
+
const count = ${{ args.limit }};
|
|
22
|
+
if (!query) throw new Error('Missing argument: query');
|
|
23
|
+
const resp = await fetch(`https://xueqiu.com/stock/search.json?code=${encodeURIComponent(query)}&size=${count}`, {credentials: 'include'});
|
|
24
|
+
if (!resp.ok) throw new Error('HTTP ' + resp.status + ' Hint: Not logged in?');
|
|
25
|
+
const d = await resp.json();
|
|
26
|
+
return (d.stocks || []).map(s => {
|
|
27
|
+
let symbol = '';
|
|
28
|
+
if (s.exchange === 'SH' || s.exchange === 'SZ' || s.exchange === 'BJ') {
|
|
29
|
+
symbol = s.code.startsWith(s.exchange) ? s.code : s.exchange + s.code;
|
|
30
|
+
} else {
|
|
31
|
+
symbol = s.code;
|
|
32
|
+
}
|
|
33
|
+
return {
|
|
34
|
+
symbol: symbol,
|
|
35
|
+
name: s.name,
|
|
36
|
+
exchange: s.exchange,
|
|
37
|
+
price: s.current,
|
|
38
|
+
changePercent: s.percentage != null ? s.percentage.toFixed(2) + '%' : null,
|
|
39
|
+
url: 'https://xueqiu.com/S/' + symbol
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
})()
|
|
43
|
+
|
|
44
|
+
- map:
|
|
45
|
+
symbol: ${{ item.symbol }}
|
|
46
|
+
name: ${{ item.name }}
|
|
47
|
+
exchange: ${{ item.exchange }}
|
|
48
|
+
price: ${{ item.price }}
|
|
49
|
+
changePercent: ${{ item.changePercent }}
|
|
50
|
+
|
|
51
|
+
- limit: ${{ args.limit }}
|
|
52
|
+
|
|
53
|
+
columns: [symbol, name, exchange, price, changePercent]
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
site: xueqiu
|
|
2
|
+
name: stock
|
|
3
|
+
description: 获取雪球股票实时行情
|
|
4
|
+
domain: xueqiu.com
|
|
5
|
+
browser: true
|
|
6
|
+
|
|
7
|
+
args:
|
|
8
|
+
symbol:
|
|
9
|
+
type: str
|
|
10
|
+
description: 股票代码,如 SH600519、SZ000858、AAPL、00700
|
|
11
|
+
|
|
12
|
+
pipeline:
|
|
13
|
+
- navigate: https://xueqiu.com
|
|
14
|
+
- evaluate: |
|
|
15
|
+
(async () => {
|
|
16
|
+
const symbol = (${{ args.symbol | json }} || '').toUpperCase();
|
|
17
|
+
if (!symbol) throw new Error('Missing argument: symbol');
|
|
18
|
+
const resp = await fetch(`https://stock.xueqiu.com/v5/stock/batch/quote.json?symbol=${encodeURIComponent(symbol)}`, {credentials: 'include'});
|
|
19
|
+
if (!resp.ok) throw new Error('HTTP ' + resp.status + ' Hint: Not logged in?');
|
|
20
|
+
const d = await resp.json();
|
|
21
|
+
if (!d.data || !d.data.items || d.data.items.length === 0) throw new Error('未找到股票: ' + symbol);
|
|
22
|
+
|
|
23
|
+
function fmtAmount(v) {
|
|
24
|
+
if (v == null) return null;
|
|
25
|
+
if (Math.abs(v) >= 1e12) return (v / 1e12).toFixed(2) + '万亿';
|
|
26
|
+
if (Math.abs(v) >= 1e8) return (v / 1e8).toFixed(2) + '亿';
|
|
27
|
+
if (Math.abs(v) >= 1e4) return (v / 1e4).toFixed(2) + '万';
|
|
28
|
+
return v.toString();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const item = d.data.items[0];
|
|
32
|
+
const q = item.quote || {};
|
|
33
|
+
const m = item.market || {};
|
|
34
|
+
|
|
35
|
+
return [{
|
|
36
|
+
name: q.name,
|
|
37
|
+
symbol: q.symbol,
|
|
38
|
+
exchange: q.exchange,
|
|
39
|
+
currency: q.currency,
|
|
40
|
+
price: q.current,
|
|
41
|
+
change: q.chg,
|
|
42
|
+
changePercent: q.percent != null ? q.percent.toFixed(2) + '%' : null,
|
|
43
|
+
open: q.open,
|
|
44
|
+
high: q.high,
|
|
45
|
+
low: q.low,
|
|
46
|
+
prevClose: q.last_close,
|
|
47
|
+
amplitude: q.amplitude != null ? q.amplitude.toFixed(2) + '%' : null,
|
|
48
|
+
volume: q.volume,
|
|
49
|
+
amount: fmtAmount(q.amount),
|
|
50
|
+
turnover_rate: q.turnover_rate != null ? q.turnover_rate.toFixed(2) + '%' : null,
|
|
51
|
+
marketCap: fmtAmount(q.market_capital),
|
|
52
|
+
floatMarketCap: fmtAmount(q.float_market_capital),
|
|
53
|
+
ytdPercent: q.current_year_percent != null ? q.current_year_percent.toFixed(2) + '%' : null,
|
|
54
|
+
market_status: m.status || null,
|
|
55
|
+
time: q.timestamp ? new Date(q.timestamp).toISOString() : null,
|
|
56
|
+
url: 'https://xueqiu.com/S/' + q.symbol
|
|
57
|
+
}];
|
|
58
|
+
})()
|
|
59
|
+
|
|
60
|
+
- map:
|
|
61
|
+
name: ${{ item.name }}
|
|
62
|
+
symbol: ${{ item.symbol }}
|
|
63
|
+
price: ${{ item.price }}
|
|
64
|
+
changePercent: ${{ item.changePercent }}
|
|
65
|
+
marketCap: ${{ item.marketCap }}
|
|
66
|
+
|
|
67
|
+
columns: [name, symbol, price, changePercent, marketCap]
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
site: xueqiu
|
|
2
|
+
name: watchlist
|
|
3
|
+
description: 获取雪球自选股列表
|
|
4
|
+
domain: xueqiu.com
|
|
5
|
+
browser: true
|
|
6
|
+
|
|
7
|
+
args:
|
|
8
|
+
category:
|
|
9
|
+
type: str # using str to prevent parsing issues like 01
|
|
10
|
+
default: "1"
|
|
11
|
+
description: "分类:1=自选(默认) 2=持仓 3=关注"
|
|
12
|
+
limit:
|
|
13
|
+
type: int
|
|
14
|
+
default: 100
|
|
15
|
+
description: 默认 100
|
|
16
|
+
|
|
17
|
+
pipeline:
|
|
18
|
+
- navigate: https://xueqiu.com
|
|
19
|
+
- evaluate: |
|
|
20
|
+
(async () => {
|
|
21
|
+
const category = parseInt(${{ args.category | json }}) || 1;
|
|
22
|
+
const resp = await fetch(`https://stock.xueqiu.com/v5/stock/portfolio/stock/list.json?size=100&category=${category}&pid=-1`, {credentials: 'include'});
|
|
23
|
+
if (!resp.ok) throw new Error('HTTP ' + resp.status + ' Hint: Not logged in?');
|
|
24
|
+
const d = await resp.json();
|
|
25
|
+
if (!d.data || !d.data.stocks) throw new Error('获取失败,可能未登录');
|
|
26
|
+
|
|
27
|
+
return d.data.stocks.map(s => ({
|
|
28
|
+
symbol: s.symbol,
|
|
29
|
+
name: s.name,
|
|
30
|
+
price: s.current,
|
|
31
|
+
change: s.chg,
|
|
32
|
+
changePercent: s.percent != null ? s.percent.toFixed(2) + '%' : null,
|
|
33
|
+
volume: s.volume,
|
|
34
|
+
url: 'https://xueqiu.com/S/' + s.symbol
|
|
35
|
+
}));
|
|
36
|
+
})()
|
|
37
|
+
|
|
38
|
+
- map:
|
|
39
|
+
symbol: ${{ item.symbol }}
|
|
40
|
+
name: ${{ item.name }}
|
|
41
|
+
price: ${{ item.price }}
|
|
42
|
+
changePercent: ${{ item.changePercent }}
|
|
43
|
+
|
|
44
|
+
- limit: ${{ args.limit }}
|
|
45
|
+
|
|
46
|
+
columns: [symbol, name, price, changePercent]
|
package/dist/clis/zhihu/hot.yaml
CHANGED
|
@@ -17,12 +17,16 @@ pipeline:
|
|
|
17
17
|
const res = await fetch('https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50', {
|
|
18
18
|
credentials: 'include'
|
|
19
19
|
});
|
|
20
|
-
const
|
|
20
|
+
const text = await res.text();
|
|
21
|
+
const d = JSON.parse(
|
|
22
|
+
text.replace(/("id"\s*:\s*)(\d{16,})/g, '$1"$2"')
|
|
23
|
+
);
|
|
21
24
|
return (d?.data || []).map((item) => {
|
|
22
25
|
const t = item.target || {};
|
|
26
|
+
const questionId = t.id == null ? '' : String(t.id);
|
|
23
27
|
return {
|
|
24
28
|
title: t.title,
|
|
25
|
-
url: 'https://www.zhihu.com/question/' +
|
|
29
|
+
url: 'https://www.zhihu.com/question/' + questionId,
|
|
26
30
|
answer_count: t.answer_count,
|
|
27
31
|
follower_count: t.follower_count,
|
|
28
32
|
heat: item.detail_text || '',
|
|
@@ -19,7 +19,9 @@ pipeline:
|
|
|
19
19
|
- evaluate: |
|
|
20
20
|
(async () => {
|
|
21
21
|
const strip = (html) => (html || '').replace(/<[^>]+>/g, '').replace(/ /g, ' ').replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&').replace(/<em>/g, '').replace(/<\/em>/g, '').trim();
|
|
22
|
-
const
|
|
22
|
+
const keyword = ${{ args.keyword | json }};
|
|
23
|
+
const limit = ${{ args.limit }};
|
|
24
|
+
const res = await fetch('https://www.zhihu.com/api/v4/search_v3?q=' + encodeURIComponent(keyword) + '&t=general&offset=0&limit=' + limit, {
|
|
23
25
|
credentials: 'include'
|
|
24
26
|
});
|
|
25
27
|
const d = await res.json();
|
package/dist/engine.d.ts
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { type CliCommand } from './registry.js';
|
|
5
5
|
import type { IPage } from './types.js';
|
|
6
|
-
export declare function discoverClis(...dirs: string[]): void
|
|
6
|
+
export declare function discoverClis(...dirs: string[]): Promise<void>;
|
|
7
7
|
export declare function executeCommand(cmd: CliCommand, page: IPage | null, kwargs: Record<string, any>, debug?: boolean): Promise<any>;
|