Init
This commit is contained in:
11
.eslintrc.yml
Normal file
11
.eslintrc.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
env:
|
||||
commonjs: true
|
||||
es6: true
|
||||
node: true
|
||||
extends: 'eslint:recommended'
|
||||
globals:
|
||||
Atomics: readonly
|
||||
SharedArrayBuffer: readonly
|
||||
parserOptions:
|
||||
ecmaVersion: 2018
|
||||
rules: {}
|
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
node_modules
|
||||
messages.json
|
||||
messages.pretty.json
|
||||
output.md
|
18
.vscode/launch.json
vendored
Normal file
18
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Launch Program",
|
||||
"skipFiles": [
|
||||
"<node_internals>/**"
|
||||
],
|
||||
"console":"integratedTerminal",
|
||||
"program": "${workspaceFolder}/index.js"
|
||||
}
|
||||
]
|
||||
}
|
91
index.js
Normal file
91
index.js
Normal file
@@ -0,0 +1,91 @@
|
||||
//@ts-check
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const read = require('./utility/readPromise')
|
||||
const writeToMarkDown = require('./utility/writeToMarkdown')
|
||||
|
||||
console.log("Started")
|
||||
read.ask("File name(messages.json)\n:").then(answer => {
|
||||
//if(answer==""){answer = "messages.json"}
|
||||
fs.exists(answer, exists => {
|
||||
if (exists) {
|
||||
fs.readFile(path.normalize(answer), (err, data) => {
|
||||
if (err) throw err;
|
||||
let readObjects = JSON.parse(data.toString())
|
||||
//console.log(readObjects.length)
|
||||
getProperties(readObjects).then(reply => {
|
||||
//console.log(`Stats:\nParts:${reply.parts}\nCount:${reply.count}`)
|
||||
reply.forEach(e=>{
|
||||
console.log(`Name: ${e.person},Count: ${e.count},Parts: ${e.parts}`)
|
||||
})
|
||||
writeToMarkDown(reply);
|
||||
read.close()
|
||||
},
|
||||
console.log
|
||||
)
|
||||
})
|
||||
} else {
|
||||
console.log("File does not exist")
|
||||
read.close()
|
||||
}
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array<Object>} objectsRead
|
||||
*/
|
||||
async function getProperties(objectsRead) {
|
||||
//let answer = await read.ask("Get List of users?(Y/N)\n:")
|
||||
//console.log("Got Answer:" + answer)
|
||||
|
||||
/** @type {Array<String>} */
|
||||
let people = objectsRead.reduce((total, element) => {
|
||||
//console.log(element)
|
||||
|
||||
element.participants.forEach(e => {
|
||||
if (!total.find(pred => { return pred == e })) {
|
||||
total.push(e)
|
||||
}
|
||||
})
|
||||
return total
|
||||
}, [])
|
||||
//console.log(people.join(", "))
|
||||
|
||||
|
||||
//Create a table
|
||||
let table = []
|
||||
for(const value in people){
|
||||
table.push({
|
||||
person: people[value],
|
||||
...await getLength(objectsRead,people[value])
|
||||
})
|
||||
}
|
||||
|
||||
table.sort((a,b)=>{return a.count-b.count})
|
||||
return table
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {Array<{participants:Array<String>,conversation:Object}>} objectsRead
|
||||
* @param {String} answer Name to search for
|
||||
* @returns {Promise<{parts:Number,count:Number}>}
|
||||
*/
|
||||
async function getLength(objectsRead,answer) {
|
||||
//let answer = await read.ask("Get which username?")
|
||||
let numbers = objectsRead.reduce((total, element) => {
|
||||
if (element.participants.find(participant => { return participant == answer })) {
|
||||
//console.log(Object.keys(element.conversation).length)
|
||||
//total+=1
|
||||
total.parts += 1
|
||||
total.count += Object.keys(element.conversation).length
|
||||
}
|
||||
return total
|
||||
}, { parts: 0, count: 0 })
|
||||
return numbers;
|
||||
}
|
1090
package-lock.json
generated
Normal file
1090
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
15
package.json
Normal file
15
package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "instagram-data-count",
|
||||
"version": "0.1.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "Christopher Rose",
|
||||
"license": "ISC",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"eslint": "^6.8.0"
|
||||
}
|
||||
}
|
7
prettyFile.js
Normal file
7
prettyFile.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const fs = require('fs')
|
||||
|
||||
fs.readFile("messages.json",(err,data)=>{
|
||||
if(err) throw err;
|
||||
let objectifiedData = JSON.parse(data)
|
||||
fs.writeFile('messages.pretty.json',JSON.stringify(objectifiedData,null,2),()=>console.log("Done"))
|
||||
})
|
22
utility/readPromise.js
Normal file
22
utility/readPromise.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const rd = require('readline').createInterface(process.stdin,process.stdout)
|
||||
|
||||
|
||||
/**
|
||||
* Get an answer from a reply
|
||||
* @param {String} askQuestion
|
||||
* @returns {Promise<String>}
|
||||
*/
|
||||
module.exports.ask = (askQuestion)=>{
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
return new Promise((resolve,reject)=>{
|
||||
rd.question(askQuestion,answer=>{
|
||||
if(answer){
|
||||
resolve(answer)
|
||||
}
|
||||
// else{
|
||||
// reject(new Error("REE NO ANSWER"))
|
||||
// }
|
||||
})
|
||||
})
|
||||
}
|
||||
module.exports.close = ()=>(rd.close())
|
4
utility/webWorker.js
Normal file
4
utility/webWorker.js
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const workers = require('worker_threads')
|
11
utility/writeToMarkdown.js
Normal file
11
utility/writeToMarkdown.js
Normal file
@@ -0,0 +1,11 @@
|
||||
//@ts-check
|
||||
/**
|
||||
* @param {Array<{parts: number;count: number;person: String;}>} data
|
||||
*/
|
||||
module.exports = (data) => {
|
||||
let writable = "Name | Count | Parts\n --- | --- | ---\n"
|
||||
data.forEach(element => {
|
||||
writable += `${element.person} | ${element.count} | ${element.parts}\n`
|
||||
});
|
||||
require('fs').writeFileSync("output.md", writable)
|
||||
}
|
Reference in New Issue
Block a user