-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.mjs
42 lines (34 loc) · 1.19 KB
/
index.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
import { readFileSync, writeFileSync } from 'fs';
import compileUSA from './compilation/USA/index.mjs';
import { fileURLToPath } from 'url';
import path from 'path';
const dir = path.dirname( fileURLToPath( import.meta.url ) );
compileUSA().then( res => {
const camPath = path.join( dir, 'cameras', 'USA.json' );
const oldCameras = JSON.parse( readFileSync( camPath ) );
let camTotal = 0;
for ( const state in { ...oldCameras, ...res }) {
let difference = 0;
if ( state in res ) {
for ( const county in res[state] ) {
difference += res[state][county].length;
camTotal += res[state][county].length;
}
}
if ( state in oldCameras ) {
for ( const county in oldCameras[state] ) {
difference -= oldCameras[state][county].length;
}
}
console.info(
`${state} has ${( difference < 0 ) ? 'lost' : 'gained'} ${Math.abs( difference )} cameras`
);
}
writeFileSync( camPath, JSON.stringify( res ) );
const readmePath = path.join( dir, 'README.md' );
let readme = readFileSync( readmePath, 'utf8' );
readme = readme.split( '\n' );
readme[1] = `A crowdsourced database of ${camTotal} traffic cameras.`;
readme = readme.join( '\n' );
writeFileSync( readmePath, readme );
});