Last active
October 4, 2023 02:07
-
-
Save takeokunn/2309597ef245763217d95650beb038d0 to your computer and use it in GitHub Desktop.
tmp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { exec } = require('child_process'); | |
const { promisify } = require('util'); | |
const routes = require('/tmp/route.json'); | |
const csv = `/tmp/06badc24-fc5b-44bc-bf75-baccb47a797b.csv`; | |
const execAsync = promisify(exec); | |
async function getRouteCount(route) { | |
const method = route.method === 'GET|HEAD' ? 'GET' : route.method; | |
const uri = route.uri.replace(/{[^/]+}/g, "[^/]+"); | |
const command = `grep -E '.*/${uri}$' ${csv} | grep '${method}' | awk -F ',' 'BEGIN {sum=0} {sum+=$1} END {print sum}'`; | |
console.log(command) | |
const { stdout } = await execAsync(command); | |
console.log(stdout.toString()) | |
return { ...route, count: stdout.toString() }; | |
} | |
const main = async () => { | |
const resultPromises = routes.map(route => getRouteCount(route)); | |
const result = await Promise.all(resultPromises); | |
console.log(result); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment