-
Notifications
You must be signed in to change notification settings - Fork 1
/
patch-provenance.mjs
57 lines (49 loc) · 1.43 KB
/
patch-provenance.mjs
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
import fs from 'fs';
import { v4 as uuidv4 } from 'uuid';
import { createHash } from 'node:crypto';
// Patch Trrack State
// Use case 1:
// Keep KE as author until October 10th
// October 16: Klaus
// October 17: Klaus Eckelt
// October 31: Klaus
// November 6th-9th: Klaus Eckelt
// November 27th: Klaus
const trrackFile = './notebooks/Use Case 2.trrack.json';
const provString = fs.readFileSync(trrackFile, 'utf8');
// parse JSON string to JSON object
const trrack = JSON.parse(provString);
if (!trrack || Object.keys(trrack.nodes).length <= 1) {
console.log('no provenance');
process.exit(0);
}
const klausEckeltUserMetaData = {
username: 'keckelt',
name: 'Klaus Eckelt',
displayName: 'Klaus Eckelt',
initials: 'KE',
avatar_url: `https://www.gravatar.com/avatar/${createHash('sha256')
.update('[email protected]')
.digest('hex')}?d=identicon`,
color: '#111111'
};
const klausUserMetaData = {
username: 'klaus',
name: 'Klaus',
displayName: 'Klaus',
initials: 'K',
avatar_url: `https://www.gravatar.com/avatar/${createHash('sha256')
.update('[email protected]')
.digest('hex')}?d=identicon`,
color: '#111111'
};
let i = 0;
for (const node of Object.values(trrack.nodes)) {
if (i > 7) {
node.meta['loops-executing-user'][0].val = klausUserMetaData;
console.log('replace user');
}
i++;
}
//console.log(JSON.stringify(trrack, null, 2));
fs.writeFileSync(trrackFile, JSON.stringify(trrack, null, 2));