commit 6d4e9bb22195f143ecbdfb7737ff9cc5cd3da85a Author: daniel muniz Date: Wed Jun 5 18:15:03 2024 -0300 init project diff --git a/package.json b/package.json new file mode 100644 index 0000000..0f97dc4 --- /dev/null +++ b/package.json @@ -0,0 +1,12 @@ +{ + "name": "netstar-categorizer", + "version": "1.0.0", + "main": "src/app.js", + "scripts": { + "dev": "node --watch src/app.js" + }, + "keywords": [], + "author": "", + "license": "ISC", + "description": "" +} diff --git a/playground.js b/playground.js new file mode 100644 index 0000000..839952a --- /dev/null +++ b/playground.js @@ -0,0 +1,18 @@ +const { spawn, exec } = require("node:child_process") + +// const subprocess = spawn('ls', ["-l"]) + +// subprocess.stdout.on("data", (data) => { +// console.log(data.toString("utf-8")) +// }) + + +exec("echo '99999.incompass.netstar-inc.com' | bin/gcf1check.sh etc check_categorize_hybrid", { cwd: '/usr/local/gcf1' }, (error, stdout, stderr)=>{ + if (error) { + console.error(error) + return + } + + console.log(stdout.trim()) + +}) \ No newline at end of file diff --git a/src/app.js b/src/app.js new file mode 100644 index 0000000..e1a3b65 --- /dev/null +++ b/src/app.js @@ -0,0 +1,10 @@ +const { GetCategoryUseCase } = require('./use-cases/get-category-use-case.js') +const categoriesMapping = require('../etc/categories-mapping.json') + + + + +const getCategoryUseCase = new GetCategoryUseCase({categoriesMapping}) + + +getCategoryUseCase.execute('utorrent.com') \ No newline at end of file diff --git a/src/etc/categories-mapping.json b/src/etc/categories-mapping.json new file mode 100644 index 0000000..afc09e6 --- /dev/null +++ b/src/etc/categories-mapping.json @@ -0,0 +1,176 @@ +[ + { + "id": "701", + "related": [ + "10005" + ] + }, + { + "id": "20066", + "related": [ + "10298" + ] + }, + { + "id": "401", + "related": [ + "10076" + ] + }, + { + "id": "402", + "related": [ + "10297, 10300" + ] + }, + { + "id": "20068", + "related": [ + "10297" + ] + }, + { + "id": "20082", + "related": [ + "10080" + ] + }, + { + "id": "204", + "related": [ + "10016, 10018" + ] + }, + { + "id": "101", + "related": [ + "10084, 10078" + ] + }, + { + "id": "301", + "related": [ + "10009, 10008" + ] + }, + { + "id": "501", + "related": [ + "10283" + ] + }, + { + "id": "305", + "related": [ + "10074" + ] + }, + { + "id": "205", + "related": [ + "10325" + ] + }, + { + "id": "211", + "related": [ + "10001, 10002, 10003" + ] + }, + { + "id": "20022", + "related": [ + "10015, 10072" + ] + }, + { + "id": "20054", + "related": [ + "10019, 10020" + ] + }, + { + "id": "20008", + "related": [ + "10120, 10105" + ] + }, + { + "id": "20091", + "related": [ + "10094" + ] + }, + { + "id": "20016", + "related": [ + "10234" + ] + }, + { + "id": "1802", + "related": [ + "10415" + ] + }, + { + "id": "20059", + "related": [ + "10144, 10141" + ] + }, + { + "id": "20053", + "related": [ + "10107, 10146" + ] + }, + { + "id": "20070", + "related": [ + "10045" + ] + }, + { + "id": "20071", + "related": [ + "10336" + ] + }, + { + "id": "20077", + "related": [ + "10329" + ] + }, + { + "id": "20013", + "related": [ + "10050, 10333" + ] + }, + { + "id": "20004", + "related": [ + "10044, 10337" + ] + }, + { + "id": "604", + "related": [ + "10149, 10163" + ] + }, + { + "id": "603", + "related": [ + "10155" + ] + }, + { + "id": "801", + "related": [ + "10279, 10266" + ] + } + ] diff --git a/src/use-cases/category-converter-use-case.js b/src/use-cases/category-converter-use-case.js new file mode 100644 index 0000000..ed6ede4 --- /dev/null +++ b/src/use-cases/category-converter-use-case.js @@ -0,0 +1,12 @@ + +class CategoryConverterUseCase { + constructor(categoriesMapping) { + this.categoriesMapping = categoriesMapping + } + + execute() { + + } +} + +module.export = { CategoryConverterUseCase } \ No newline at end of file diff --git a/src/use-cases/get-category-use-case.js b/src/use-cases/get-category-use-case.js new file mode 100644 index 0000000..24fb16a --- /dev/null +++ b/src/use-cases/get-category-use-case.js @@ -0,0 +1,27 @@ +const { exec } = require("node:child_process") + +class GetCategoryUseCase { + constructor({categoriesMapping}) { + this.categoriesMapping = categoriesMapping + } + + execute(domain) { + exec(`echo ${domain} | bin/gcf1check.sh etc check_categorize_hybrid`, { cwd: '/usr/local/gcf1' }, (error, stdout, stderr)=>{ + if (error) { + console.error(error) + return + } + + const outputParts = stdout.split(/\s+/); // Split by whitespace + if (outputParts[3]) { + const categoryId = outputParts[2]; + console.log({ categoryId }); + } else { + console.log({ error: 'Category ID not found' }); + } + }) + } +} + +module.exports = { GetCategoryUseCase } +