Skip to content

Instantly share code, notes, and snippets.

@Jaid
Created Oct 6, 2021
Embed
What would you like to do?
Analyze streamer earnings in Twitch leak
import {globby} from "globby"
import fs from "node:fs/promises"
import path from "node:path"
import * as fflate from "fflate"
import csvParse from "csv-parse"
import lodash from "lodash-es"
const twitchPayoutsFolder = "C:/Users/Jaid/Desktop/twitch-payouts/all_revenues"
let allGross = 0
let allRows = 0
let totalGross = 0
const csvFiles = await globby("**/*.gz", {
cwd: twitchPayoutsFolder,
stats: true
})
const csvIndex = csvFiles.map(file => {
return {
file: file.path,
size: file.stats.size,
id: file.path.slice(0, 7)
}
})
const csvIndexSorted = lodash.sortBy(lodash.uniqBy(lodash.reverse(lodash.sortBy(csvIndex, "size")), "id"), "id")
let i = 0
console.log("Collected " + csvIndexSorted.length + " CSVs")
for (const csvEntry of csvIndexSorted) {
const file = csvEntry.file
i++
const absoluteFile = path.join(twitchPayoutsFolder, file)
console.log("[" + i + "/" + csvIndexSorted.length + "] Looking at " + csvEntry.file)
const inputData = await fs.readFile(absoluteFile)
const decompressedBuffer = fflate.gunzipSync(inputData)
const csvString = fflate.strFromU8(decompressedBuffer, true)
csvParse(csvString, (_error, rows) => {
let currentRow = 0
for (const row of rows) {
currentRow++
if (currentRow === 1) {
continue
}
const [userId, _payoutId, adGross, subGross, bitsGross, developerGross, extensionGross, primeGross, bitsAdGross, fuelGross, revGross] = row
if (userId !== "45044816") { // MontanaBlack88
// if (userId !== "65887522") { // Jaidchen
continue
}
const gross = Number(adGross) + Number(subGross) + Number(bitsGross) + Number(developerGross) + Number(extensionGross) + Number(primeGross) + Number(bitsAdGross) + Number(fuelGross) + Number(revGross)
const grossEuro = gross * 0.87
console.log("-> Found gross: " + gross + " $ (or " + grossEuro + " €)")
totalGross += grossEuro
console.log("-> Total gross is now: " + Math.trunc(totalGross) + " €")
}
console.log("Checked rows: " + currentRow)
allRows += currentRow
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment