Add aliases for --splatnet2-monitor-* options and don't require setting a directory for downloading Parental Controls and SplatNet 2 data

This commit is contained in:
Samuel Elliott
2022-03-25 19:01:31 +00:00
parent 085d8a6a54
commit 74c6f71a76
5 changed files with 55 additions and 24 deletions

View File

@@ -12,14 +12,13 @@ import { Challenge, NicknameAndIcon, Records, Stages } from '../../api/splatnet2
const debug = createDebug('cli:splatnet2:dump-records');
export const command = 'dump-records <directory>';
export const command = 'dump-records [directory]';
export const desc = 'Download all other records';
export function builder(yargs: Argv<ParentArguments>) {
return yargs.positional('directory', {
describe: 'Directory to write record data to',
type: 'string',
demandOption: true,
}).option('user', {
describe: 'Nintendo Account ID',
type: 'string',
@@ -69,7 +68,9 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
await storage.getItem('NintendoAccountToken.' + usernsid);
const {splatnet} = await getIksmToken(storage, token, argv.zncProxyUrl, argv.autoUpdateSession);
await mkdirp(argv.directory);
const directory = argv.directory ?? path.join(argv.dataPath, 'splatnet2');
await mkdirp(directory);
const [records, stages, activefestivals, timeline] = await Promise.all([
splatnet.getRecords(),
@@ -82,30 +83,30 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
const updated = argv.newRecords ? new Date(records.records.update_time * 1000) : undefined;
if (argv.userRecords) {
await dumpRecords(argv.directory, records.records.unique_id, records,
await dumpRecords(directory, records.records.unique_id, records,
nickname_and_icons.nickname_and_icons[0], updated);
}
if (argv.profileImage) {
await dumpProfileImage(splatnet, argv.directory, records.records.unique_id, stages,
await dumpProfileImage(splatnet, directory, records.records.unique_id, stages,
nickname_and_icons.nickname_and_icons[0],
argv.favouriteStage, argv.favouriteColour, updated);
}
if (argv.challenges) {
await dumpChallenges(splatnet, argv.directory, records.records.unique_id,
await dumpChallenges(splatnet, directory, records.records.unique_id,
records.challenges.archived_challenges, 1);
await dumpChallenges(splatnet, argv.directory, records.records.unique_id,
await dumpChallenges(splatnet, directory, records.records.unique_id,
records.challenges.archived_challenges_octa, 2);
}
if (argv.heroRecords) {
await dumpHeroRecords(splatnet, argv.directory, records.records.unique_id);
await dumpHeroRecords(splatnet, directory, records.records.unique_id);
}
if (argv.timeline) {
const filename = 'splatnet2-timeline-' + records.records.unique_id + '-' + Date.now() + '.json';
const file = path.join(argv.directory, filename);
const file = path.join(directory, filename);
debug('Writing timeline %s', filename);
await fs.writeFile(file, JSON.stringify(timeline, null, 4) + '\n', 'utf-8');

View File

@@ -11,14 +11,13 @@ import fetch from 'node-fetch';
const debug = createDebug('cli:splatnet2:dump-results');
export const command = 'dump-results <directory>';
export const command = 'dump-results [directory]';
export const desc = 'Download all battle and coop results';
export function builder(yargs: Argv<ParentArguments>) {
return yargs.positional('directory', {
describe: 'Directory to write record data to',
type: 'string',
demandOption: true,
}).option('user', {
describe: 'Nintendo Account ID',
type: 'string',
@@ -58,18 +57,20 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
await storage.getItem('NintendoAccountToken.' + usernsid);
const {splatnet} = await getIksmToken(storage, token, argv.zncProxyUrl, argv.autoUpdateSession);
await mkdirp(argv.directory);
const directory = argv.directory ?? path.join(argv.dataPath, 'splatnet2');
await mkdirp(directory);
const updated = argv.checkUpdated ? new Date((await splatnet.getRecords()).records.update_time * 1000) : undefined;
const records = await splatnet.getRecords();
if (argv.battles) {
await dumpResults(splatnet, argv.directory, records.records.unique_id,
await dumpResults(splatnet, directory, records.records.unique_id,
argv.battleImages, argv.battleSummaryImage, updated);
}
if (argv.coop) {
await dumpCoopResults(splatnet, argv.directory, records.records.unique_id, updated);
await dumpCoopResults(splatnet, directory, records.records.unique_id, updated);
}
}