-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathparsegameidtime.ts
More file actions
53 lines (46 loc) · 1.78 KB
/
parsegameidtime.ts
File metadata and controls
53 lines (46 loc) · 1.78 KB
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
import * as fsp from 'fs/promises';
import * as fs from 'fs';
import { exec, execSync } from 'child_process';
import { timeStamp } from 'console';
async function main () {
const file = "gameidtime.txt";
const content = await fsp.readFile(file, { encoding: "utf8" });
const rows = content.split("\n");
const games = rows.map(g => {
g = g.trim();
const sections = g.split(" ");
const [gameName, gameID, ...gameTime] = sections;
let gameDate = new Date(gameTime.join(" "));
if (isNaN(gameDate.getTime())){
gameDate = new Date("March 9, 2025")
}
return {
gameName,
gameID,
gameDate
}
});
let workingGames = games.filter(g => !isNaN(g.gameDate.getTime())).sort((a, b) => a.gameDate.getTime() - b.gameDate.getTime());
const command = (gameID: string, timestamp: number) => {
fs.writeFileSync("values.json", JSON.stringify({ ":u": { "N": `${timestamp}` } }))
fs.writeFileSync("key.json", JSON.stringify({ "gameID": { "S": gameID } }));
return `aws dynamodb update-item
--table-name games_list
--key file://key.json
--update-expression "SET uploadedTimestamp = :u, updatedTimestamp = :u"
--expression-attribute-values file://values.json`
}
let lastTime = 0;
let inc = 0;
workingGames.forEach(game => {
let add = lastTime == game.gameDate.getTime() ? ++inc : (inc = 0);
lastTime = game.gameDate.getTime();
let c = command(game.gameID, game.gameDate.getTime() + add);
console.log(">>>>", c);
execSync(c.split("\n").map(s => s.trim()).join(" "));
console.log("Finished", game.gameName)
})
}
main().then(() => {
console.log("\n\nDone")
}).catch(console.error)