@jackwener/opencli 0.1.2 → 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.
Files changed (72) hide show
  1. package/CLI-CREATOR.md +51 -72
  2. package/README.md +8 -5
  3. package/README.zh-CN.md +8 -5
  4. package/SKILL.md +27 -14
  5. package/dist/browser.d.ts +7 -0
  6. package/dist/browser.js +85 -2
  7. package/dist/clis/bilibili/dynamic.d.ts +1 -0
  8. package/dist/clis/bilibili/dynamic.js +33 -0
  9. package/dist/clis/bilibili/ranking.d.ts +1 -0
  10. package/dist/clis/bilibili/ranking.js +24 -0
  11. package/dist/clis/reddit/frontpage.yaml +30 -0
  12. package/dist/clis/reddit/hot.yaml +3 -2
  13. package/dist/clis/reddit/search.yaml +34 -0
  14. package/dist/clis/reddit/subreddit.yaml +39 -0
  15. package/dist/clis/twitter/bookmarks.yaml +85 -0
  16. package/dist/clis/twitter/profile.d.ts +1 -0
  17. package/dist/clis/twitter/profile.js +56 -0
  18. package/dist/clis/twitter/search.d.ts +1 -0
  19. package/dist/clis/twitter/search.js +60 -0
  20. package/dist/clis/twitter/timeline.d.ts +1 -0
  21. package/dist/clis/twitter/timeline.js +47 -0
  22. package/dist/clis/xiaohongshu/user.d.ts +1 -0
  23. package/dist/clis/xiaohongshu/user.js +40 -0
  24. package/dist/clis/xueqiu/feed.yaml +53 -0
  25. package/dist/clis/xueqiu/hot-stock.yaml +49 -0
  26. package/dist/clis/xueqiu/hot.yaml +46 -0
  27. package/dist/clis/xueqiu/search.yaml +53 -0
  28. package/dist/clis/xueqiu/stock.yaml +67 -0
  29. package/dist/clis/xueqiu/watchlist.yaml +46 -0
  30. package/dist/clis/zhihu/hot.yaml +6 -2
  31. package/dist/clis/zhihu/search.yaml +3 -1
  32. package/dist/engine.d.ts +1 -1
  33. package/dist/engine.js +9 -1
  34. package/dist/main.d.ts +1 -1
  35. package/dist/main.js +10 -3
  36. package/dist/output.d.ts +1 -1
  37. package/dist/output.js +12 -8
  38. package/dist/pipeline/steps/intercept.js +56 -29
  39. package/dist/pipeline/template.js +74 -15
  40. package/dist/pipeline/template.test.js +24 -0
  41. package/dist/types.d.ts +6 -0
  42. package/package.json +1 -1
  43. package/src/browser.ts +88 -5
  44. package/src/clis/bilibili/dynamic.ts +34 -0
  45. package/src/clis/bilibili/ranking.ts +25 -0
  46. package/src/clis/reddit/frontpage.yaml +30 -0
  47. package/src/clis/reddit/hot.yaml +3 -2
  48. package/src/clis/reddit/search.yaml +34 -0
  49. package/src/clis/reddit/subreddit.yaml +39 -0
  50. package/src/clis/twitter/bookmarks.yaml +85 -0
  51. package/src/clis/twitter/profile.ts +61 -0
  52. package/src/clis/twitter/search.ts +65 -0
  53. package/src/clis/twitter/timeline.ts +50 -0
  54. package/src/clis/xiaohongshu/user.ts +45 -0
  55. package/src/clis/xueqiu/feed.yaml +53 -0
  56. package/src/clis/xueqiu/hot-stock.yaml +49 -0
  57. package/src/clis/xueqiu/hot.yaml +46 -0
  58. package/src/clis/xueqiu/search.yaml +53 -0
  59. package/src/clis/xueqiu/stock.yaml +67 -0
  60. package/src/clis/xueqiu/watchlist.yaml +46 -0
  61. package/src/clis/zhihu/hot.yaml +6 -2
  62. package/src/clis/zhihu/search.yaml +3 -1
  63. package/src/engine.ts +10 -1
  64. package/src/main.ts +9 -3
  65. package/src/output.ts +10 -6
  66. package/src/pipeline/steps/intercept.ts +58 -28
  67. package/src/pipeline/template.test.ts +24 -0
  68. package/src/pipeline/template.ts +72 -14
  69. package/src/types.ts +3 -0
  70. package/dist/clis/index.d.ts +0 -22
  71. package/dist/clis/index.js +0 -34
  72. package/src/clis/index.ts +0 -46
@@ -0,0 +1,39 @@
1
+ site: reddit
2
+ name: subreddit
3
+ description: Get posts from a specific Subreddit
4
+ domain: reddit.com
5
+ strategy: cookie
6
+ browser: true
7
+
8
+ args:
9
+ name:
10
+ type: string
11
+ required: true
12
+ sort:
13
+ type: string
14
+ default: hot
15
+ description: "Sorting method: hot, new, top, rising"
16
+ limit:
17
+ type: int
18
+ default: 15
19
+
20
+ columns: [title, author, upvotes, comments, url]
21
+
22
+ pipeline:
23
+ - navigate: https://www.reddit.com
24
+ - evaluate: |
25
+ (async () => {
26
+ let sub = '${{ args.name }}';
27
+ if (sub.startsWith('r/')) sub = sub.slice(2);
28
+ const sort = '${{ args.sort }}';
29
+ const res = await fetch('/r/' + sub + '/' + sort + '.json?limit=${{ args.limit }}', { credentials: 'include' });
30
+ const j = await res.json();
31
+ return j?.data?.children || [];
32
+ })()
33
+ - map:
34
+ title: ${{ item.data.title }}
35
+ author: ${{ item.data.author }}
36
+ upvotes: ${{ item.data.score }}
37
+ comments: ${{ item.data.num_comments }}
38
+ url: https://www.reddit.com${{ item.data.permalink }}
39
+ - limit: ${{ args.limit }}
@@ -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,61 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+
3
+ cli({
4
+ site: 'twitter',
5
+ name: 'profile',
6
+ description: 'Fetch tweets from a user profile',
7
+ domain: 'x.com',
8
+ strategy: Strategy.INTERCEPT,
9
+ browser: true,
10
+ args: [
11
+ { name: 'username', type: 'string', required: true },
12
+ { name: 'limit', type: 'int', default: 15 },
13
+ ],
14
+ columns: ['id', 'text', 'likes', 'views', 'url'],
15
+ func: async (page, kwargs) => {
16
+ // Navigate to user profile via search for reliability
17
+ await page.goto(`https://x.com/search?q=from:${kwargs.username}&f=live`);
18
+ await page.wait(5);
19
+
20
+ // Inject XHR interceptor
21
+ await page.installInterceptor('SearchTimeline');
22
+
23
+ // Trigger API by scrolling
24
+ await page.autoScroll({ times: 3, delayMs: 2000 });
25
+
26
+ // Retrieve data
27
+ const requests = await page.getInterceptedRequests();
28
+ if (!requests || requests.length === 0) return [];
29
+
30
+ let results: any[] = [];
31
+ for (const req of requests) {
32
+ try {
33
+ const insts = req.data.data.search_by_raw_query.search_timeline.timeline.instructions;
34
+ const addEntries = insts.find((i: any) => i.type === 'TimelineAddEntries');
35
+ if (!addEntries) continue;
36
+
37
+ for (const entry of addEntries.entries) {
38
+ if (!entry.entryId.startsWith('tweet-')) continue;
39
+
40
+ let tweet = entry.content?.itemContent?.tweet_results?.result;
41
+ if (!tweet) continue;
42
+
43
+ if (tweet.__typename === 'TweetWithVisibilityResults' && tweet.tweet) {
44
+ tweet = tweet.tweet;
45
+ }
46
+
47
+ results.push({
48
+ id: tweet.rest_id,
49
+ text: tweet.legacy?.full_text || '',
50
+ likes: tweet.legacy?.favorite_count || 0,
51
+ views: tweet.views?.count || '0',
52
+ url: `https://x.com/i/status/${tweet.rest_id}`
53
+ });
54
+ }
55
+ } catch (e) {
56
+ }
57
+ }
58
+
59
+ return results.slice(0, kwargs.limit);
60
+ }
61
+ });
@@ -0,0 +1,65 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+
3
+ cli({
4
+ site: 'twitter',
5
+ name: 'search',
6
+ description: 'Search Twitter/X for tweets',
7
+ domain: 'x.com',
8
+ strategy: Strategy.INTERCEPT, // Use intercept strategy
9
+ browser: true,
10
+ args: [
11
+ { name: 'query', type: 'string', required: true },
12
+ { name: 'limit', type: 'int', default: 15 },
13
+ ],
14
+ columns: ['id', 'author', 'text', 'likes', 'views', 'url'],
15
+ func: async (page, kwargs) => {
16
+ // 1. Navigate to the search page
17
+ const q = encodeURIComponent(kwargs.query);
18
+ await page.goto(`https://x.com/search?q=${q}&f=top`);
19
+ await page.wait(5);
20
+
21
+ // 2. Inject XHR interceptor
22
+ await page.installInterceptor('SearchTimeline');
23
+
24
+ // 3. Trigger API by scrolling
25
+ await page.autoScroll({ times: 3, delayMs: 2000 });
26
+
27
+ // 4. Retrieve data
28
+ const requests = await page.getInterceptedRequests();
29
+ if (!requests || requests.length === 0) return [];
30
+
31
+ let results: any[] = [];
32
+ for (const req of requests) {
33
+ try {
34
+ const insts = req.data.data.search_by_raw_query.search_timeline.timeline.instructions;
35
+ const addEntries = insts.find((i: any) => i.type === 'TimelineAddEntries');
36
+ if (!addEntries) continue;
37
+
38
+ for (const entry of addEntries.entries) {
39
+ if (!entry.entryId.startsWith('tweet-')) continue;
40
+
41
+ let tweet = entry.content?.itemContent?.tweet_results?.result;
42
+ if (!tweet) continue;
43
+
44
+ // Handle retweet wrapping
45
+ if (tweet.__typename === 'TweetWithVisibilityResults' && tweet.tweet) {
46
+ tweet = tweet.tweet;
47
+ }
48
+
49
+ results.push({
50
+ id: tweet.rest_id,
51
+ author: tweet.core?.user_results?.result?.legacy?.screen_name || 'unknown',
52
+ text: tweet.legacy?.full_text || '',
53
+ likes: tweet.legacy?.favorite_count || 0,
54
+ views: tweet.views?.count || '0',
55
+ url: `https://x.com/i/status/${tweet.rest_id}`
56
+ });
57
+ }
58
+ } catch (e) {
59
+ // ignore parsing errors for individual payloads
60
+ }
61
+ }
62
+
63
+ return results.slice(0, kwargs.limit);
64
+ }
65
+ });
@@ -0,0 +1,50 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+
3
+ cli({
4
+ site: 'twitter',
5
+ name: 'timeline',
6
+ description: 'Twitter Home Timeline',
7
+ domain: 'x.com',
8
+ strategy: Strategy.COOKIE,
9
+ args: [
10
+ { name: 'limit', type: 'int', default: 20 },
11
+ ],
12
+ columns: ['responseType', 'first'],
13
+ func: async (page, kwargs) => {
14
+ await page.goto('https://x.com/home');
15
+ await page.wait(5);
16
+ // Inject the fetch interceptor manually to see exactly what happens
17
+ await page.evaluate(`
18
+ () => {
19
+ window.__intercept_data = [];
20
+ const origFetch = window.fetch;
21
+ window.fetch = async function(...args) {
22
+ let u = typeof args[0] === 'string' ? args[0] : (args[0] && args[0].url) || '';
23
+ const res = await origFetch.apply(this, args);
24
+ setTimeout(async () => {
25
+ try {
26
+ if (u.includes('HomeTimeline')) {
27
+ const clone = res.clone();
28
+ const j = await clone.json();
29
+ window.__intercept_data.push(j);
30
+ }
31
+ } catch(e) {}
32
+ }, 0);
33
+ return res;
34
+ };
35
+ }
36
+ `);
37
+
38
+ // trigger scroll
39
+ for(let i=0; i<3; i++) {
40
+ await page.evaluate('() => window.scrollTo(0, document.body.scrollHeight)');
41
+ await page.wait(2);
42
+ }
43
+
44
+ // extract
45
+ const data = await page.evaluate('() => window.__intercept_data');
46
+ if (!data || data.length === 0) return [{responseType: 'no data captured'}];
47
+
48
+ return [{responseType: `captured ${data.length} responses`, first: JSON.stringify(data[0]).substring(0,300)}];
49
+ }
50
+ });
@@ -0,0 +1,45 @@
1
+ import { cli, Strategy } from '../../registry.js';
2
+
3
+ cli({
4
+ site: 'xiaohongshu',
5
+ name: 'user',
6
+ description: 'Get user notes from Xiaohongshu',
7
+ domain: 'xiaohongshu.com',
8
+ strategy: Strategy.INTERCEPT,
9
+ browser: true,
10
+ args: [
11
+ { name: 'id', type: 'string', required: true },
12
+ { name: 'limit', type: 'int', default: 15 },
13
+ ],
14
+ columns: ['id', 'title', 'type', 'likes', 'url'],
15
+ func: async (page, kwargs) => {
16
+ await page.goto(`https://www.xiaohongshu.com/user/profile/${kwargs.id}`);
17
+ await page.wait(5);
18
+
19
+ await page.installInterceptor('v1/user/posted');
20
+
21
+ // Trigger API by scrolling
22
+ await page.autoScroll({ times: 2, delayMs: 2000 });
23
+
24
+ // Retrieve data
25
+ const requests = await page.getInterceptedRequests();
26
+ if (!requests || requests.length === 0) return [];
27
+
28
+ let results: any[] = [];
29
+ for (const req of requests) {
30
+ if (req.data && req.data.data && req.data.data.notes) {
31
+ for (const note of req.data.data.notes) {
32
+ results.push({
33
+ id: note.note_id || note.id,
34
+ title: note.display_title || '',
35
+ type: note.type || '',
36
+ likes: note.interact_info?.liked_count || '0',
37
+ url: `https://www.xiaohongshu.com/explore/${note.note_id || note.id}`
38
+ });
39
+ }
40
+ }
41
+ }
42
+
43
+ return results.slice(0, kwargs.limit);
44
+ }
45
+ });
@@ -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(/&nbsp;/g, ' ').replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/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(/&nbsp;/g, ' ').replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/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]