/ clis / nowcoder / practice.js
practice.js
 1  import { cli } from '@jackwener/opencli/registry';
 2  
 3  cli({
 4      site: 'nowcoder',
 5      name: 'practice',
 6      description: 'Categorized practice questions with progress',
 7      domain: 'www.nowcoder.com',
 8      args: [
 9          { name: 'job', type: 'str', default: '11226', help: 'Career ID (11226=Software, 11227=Hardware, 11229=Product, 11230=Finance)' },
10          { name: 'limit', type: 'int', default: 20, help: 'Number of items' },
11      ],
12      columns: ['category', 'subject', 'total', 'done', 'remaining'],
13      pipeline: [
14          { navigate: 'https://www.nowcoder.com' },
15          { evaluate: `(async () => {
16    const jobId = \${{ args.job | json }};
17    const limit = \${{ args.limit }};
18    const r = await fetch('https://gw-c.nowcoder.com/api/sparta/intelligent/getPCIntelligentList?jobId=' + jobId, {credentials: 'include'});
19    const d = await r.json();
20    if (!d.success) throw new Error(d.msg || 'API failed');
21    const all = [];
22    for (const tag of (d.data?.tags || [])) {
23      for (const item of (tag.items || [])) {
24        all.push({
25          category: tag.title || 'recommended',
26          subject: item.title,
27          total: item.tcount,
28          done: item.rcount,
29          remaining: item.leftCount,
30        });
31      }
32    }
33    return all.slice(0, limit);
34  })()
35  ` },
36      ],
37  });