-
Notifications
You must be signed in to change notification settings - Fork 9
/
add_user.ts
44 lines (40 loc) · 1.34 KB
/
add_user.ts
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
import { getAcSubmissions, getToday, getWeekStartAndEnd } from './utils';
import type { IUser } from './typings';
import * as fs from 'fs';
import * as path from 'path';
const today = getToday();
const weekDateList = getWeekStartAndEnd(today);
const newUsers: IUser[] = [
// {
// userName: '',
// userId: '',
// },
];
const [userName, userId, lcus] = process.argv.slice(2, 5);
if (userId) {
const user: IUser = { userName, userId };
if (lcus === '1') {
user.lcus = true;
}
newUsers.push(user);
}
addUser(newUsers).catch((e) => console.log(e));
// 获取新增人员,当前周的刷题记录
// 其实可以 getAcSubmissions() 修改成直接扫描当前可以获取到的全部记录,重新记录
// 懒得改了...
async function addUser(newUsers: IUser[]) {
if (!newUsers.length) return;
const userFilePath = path.resolve(__dirname, `../data/common/user.json`);
const userJSON = fs.readFileSync(userFilePath, { encoding: 'utf-8' });
const users = JSON.parse(userJSON);
for (let i = 0; i < newUsers.length; i++) {
const user = newUsers[i];
users.push(user);
for (let j = 0; j < weekDateList.length; j++) {
const date = weekDateList[j];
await getAcSubmissions(user, date);
if (date === today) break;
}
}
fs.writeFileSync(userFilePath, JSON.stringify(users, null, 2), { encoding: 'utf-8' });
}