-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
executable file
·89 lines (74 loc) · 3.15 KB
/
index.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env node
import { program } from 'commander';
import { historicOdds, nextMatches } from './lib/commands/index.js';
import { leaguesUrlsMap, oddsFormatMap } from './lib/constants.js';
import { exportToS3, exportToDir } from './lib/exporters.js'
import { readFileSync } from 'fs';
const packageJson = JSON.parse(readFileSync(new URL('./package.json', import.meta.url)));
program
.version(packageJson.version)
.description('A CLI tool for scraping soccer odds from the odds portal site.')
.command('help')
.description('show available commands')
.action(() => program.help());;
program
.command('historic <leagueName> <startYear> <endYear>')
.description('historic scrape of odds in the given league')
.requiredOption('--odds-format <format>', 'the desired odds format')
.option('--s3 <bucketName>', 'S3 bucket name to store the JSON file')
.option('--local <directory>', 'Local output directory for JSON file')
.action(async (leagueName, startYear, endYear, options) => {
if (startYear > endYear) {
console.error('Error: startYear must be less than endYear');
return;
}
const oddsFormat = options.oddsFormat;
if (options.s3 && options.local) {
console.error('Error: Cannot use both --s3 and --local options. Choose one.');
return;
} else if (options.s3) {
const s3Exporter = exportToS3(options.s3)
await historicOdds(leagueName, startYear, endYear, oddsFormat, s3Exporter);
} else if (options.local) {
const localExport = exportToDir(options.local)
await historicOdds(leagueName, startYear, endYear, oddsFormat, localExport);
}
});
program
.command('next-matches <leagueName>')
.description('scrape of odds in the given league')
.requiredOption('--odds-format <format>', 'the desired odds format')
.option('--s3 <bucketName>', 'S3 bucket name to store the JSON file')
.option('--local <directory>', 'Local output directory for JSON file')
.action(async (leagueName, options) => {
const oddsFormat = options.oddsFormat;
if (options.s3 && options.local) {
logger.error('Error: Cannot use both --s3 and --local options. Choose one.');
return;
} else if (options.s3) {
const s3Exporter = exportToS3(options.s3)
await nextMatches(leagueName, oddsFormat, s3Exporter);
} else if (options.local) {
const localExport = exportToDir(options.local)
await nextMatches(leagueName, oddsFormat, localExport);
}
});
program
.command('soccer-leagues')
.description('List the available leagues')
.action(() => {
console.log('Available leagues:');
Object.keys(leaguesUrlsMap).forEach((league) => {
console.log(`- ${league}`);
});
});
program
.command('odds-format')
.description('List the available odds format')
.action(() => {
console.log('Available format:');
Object.keys(oddsFormatMap).forEach((format) => {
console.log(`- ${format}`);
});
});
program.parse(process.argv);