Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "wazza", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Parses whatsapp backup txt file to json or csv formats", | ||
@@ -29,2 +29,3 @@ "main": "src/index.js", | ||
"@oclif/plugin-help": "^2.2.0", | ||
"cli-ux": "^5.3.0", | ||
"extract-emoji": "^1.0.2", | ||
@@ -31,0 +32,0 @@ "json2csv": "^4.5.1", |
# Wazza | ||
Wazza is a utility to parse whatsapp backup files to csv or json file formats. | ||
It supports csv and json file formats. | ||
** only tested for group backups ** | ||
Wazza is a utility to parse one or multiple whatsapp backup files into csv or json file formats. **only tested for group backups** | ||
## Features: | ||
- √ group chat exports | ||
- ? one to one chat exports | ||
- √ csv and json file formats | ||
- √ individual .txt files | ||
- √ directories of .txt (files are combined into one csv or json export) | ||
## How to export Whatsapp group conversations. | ||
@@ -28,2 +34,20 @@ | ||
If you have a folder with multiple exports from different channels, | ||
but you want to combine them into one single csv or json file, you can | ||
pass a folder as an argument instead of a file. | ||
Just make sure all files have `.txt` extension. | ||
Example, given you have a folder called `exports/` than contains one or more `.txt` files. | ||
``` | ||
wazza exports/ > export.csv | ||
``` | ||
or | ||
``` | ||
wazza -f json exports/ > export.json | ||
``` | ||
and the export file will contain the combination of all exported .txt files. | ||
## Options | ||
@@ -30,0 +54,0 @@ |
#!/usr/bin/env node | ||
const { Command, flags } = require("@oclif/command"); | ||
const { CLIError } = require("@oclif/errors"); | ||
const readFile = require("./lib/readFile"); | ||
const toCSV = require("./lib/toCSV"); | ||
const { Command, flags } = require("@oclif/command"); | ||
const { CLIError } = require("@oclif/errors"); | ||
const utils = require("./lib/utils"); | ||
const { cli } = require("cli-ux"); | ||
@@ -11,2 +13,40 @@ class WazzaCommand extends Command { | ||
const { flags, args } = this.parse(WazzaCommand); | ||
if (utils.isDirectory(args.input)) { | ||
const confirmation = await cli.confirm( | ||
`${ | ||
args.input | ||
} is a directory, wazza will aggregate all txt files into one ${ | ||
flags.format | ||
} file, continue ?` | ||
); | ||
if (confirmation) { | ||
const files = utils.getDirFiles(args.input); | ||
let header = true; | ||
if (flags.format === "json") { | ||
const datas = []; | ||
await Promise.all( | ||
files.map(async file => { | ||
const data = await readFile(args.input + file, flags.date || ""); | ||
datas.push(data); | ||
}) | ||
); | ||
console.log(JSON.stringify(Array.prototype.concat.apply([], datas))); | ||
process.exit(0); | ||
} else if (flags.format === "csv") { | ||
await Promise.all( | ||
files.map(async file => { | ||
const data = await readFile(args.input + file, flags.date || ""); | ||
console.log(toCSV(data, header)); | ||
if (header) { | ||
header = false; | ||
} | ||
}) | ||
); | ||
process.exit(0); | ||
} | ||
} else { | ||
process.exit(0); | ||
} | ||
} | ||
const data = await readFile(args.input, flags.date || ""); | ||
@@ -23,7 +63,15 @@ | ||
WazzaCommand.description = `Wazza is a whatsapp backup parser | ||
Features: | ||
- √ group chat exports | ||
- ? one to one chat exports | ||
- √ csv and json file formats | ||
- √ individual .txt files | ||
- √ directories of .txt (files are combined into one csv or json export) | ||
It supports csv and json file formats | ||
- Example, exporting to csv: | ||
wazza _chat.txt > export.csv | ||
- Example, exporting a folder that contains several .txt exported files: | ||
wazza ./exports/ > export.csv | ||
- Example exporting to json: | ||
@@ -30,0 +78,0 @@ wazza -f json _chat.txt > export.json |
const { parse } = require("json2csv"); | ||
const toCSV = content => { | ||
const toCSV = (content, header = true) => { | ||
const fields = [ | ||
@@ -5,0 +5,0 @@ "platform", |
@@ -0,1 +1,5 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const { CLIError } = require("@oclif/errors"); | ||
module.exports = { | ||
@@ -17,3 +21,16 @@ extractNumber: line => { | ||
} | ||
}, | ||
isDirectory: path => fs.lstatSync(path).isDirectory(), | ||
getDirFiles: directoryPath => { | ||
try { | ||
const files = fs.readdirSync(directoryPath); | ||
const textFiles = []; | ||
files.forEach(function(file) { | ||
if (path.extname(file) === ".txt") textFiles.push(file); | ||
}); | ||
return textFiles; | ||
} catch (err) { | ||
throw new CLIError(`Unable to scan directory ${directoryPath}`); | ||
} | ||
} | ||
}; |
9781
218
83
13
2
+ Addedcli-ux@^5.3.0
+ Added@oclif/screen@1.0.4(transitive)
+ Addedansi-escapes@4.3.2(transitive)
+ Addedansicolors@0.3.2(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedcardinal@2.1.1(transitive)
+ Addedcli-progress@3.12.0(transitive)
+ Addedcli-ux@5.6.7(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedextract-stack@2.0.0(transitive)
+ Addedhyperlinker@1.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addednatural-orderby@2.0.3(transitive)
+ Addedobject-treeify@1.1.33(transitive)
+ Addedpassword-prompt@1.1.3(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedredeyed@2.1.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedsupports-color@8.1.1(transitive)
+ Addedsupports-hyperlinks@2.3.0(transitive)
+ Addedtype-fest@0.21.3(transitive)
+ Addedwhich@2.0.2(transitive)