Skip to content

Instantly share code, notes, and snippets.

@kaz
Created February 26, 2020 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaz/7d31724e3819b1ba60a2e3c31afaed9f to your computer and use it in GitHub Desktop.
Save kaz/7d31724e3819b1ba60a2e3c31afaed9f to your computer and use it in GitHub Desktop.
"use strict";
const {WebClient} = require("@slack/web-api");
const fs = require("fs").promises;
const web = new WebClient("xoxp-XXXXXXXXXXXXXX");
(async () => {
while(true){
const cursor = JSON.parse(await fs.readFile("cursor.json").catch(() => "null"));
const data = JSON.parse(await fs.readFile("data.json").catch(() => "[]"));
console.log(data.length, cursor);
const res = await web.conversations.history({
channel: "CXXXXXXXXXXXXX",
limit: 1000,
cursor,
});
await fs.writeFile("cursor.json", JSON.stringify(res.response_metadata.next_cursor));
await fs.writeFile("data.json", JSON.stringify(data.concat(res.messages)));
}
})();
"use strict";
const result = {};
require("./data.json").forEach(msg => {
if(!msg.user){
return;
}
msg.text.replace(/github\.com\/([-\w]+\/[-\w]+)/, (_, key) => {
if(!(key in result)){
result[key] = 0;
}
++result[key];
});
});
Object.entries(result).sort(([, c1], [, c2]) => c2 - c1).forEach(([key, count]) => console.log(count, key));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment