Skip to content

Instantly share code, notes, and snippets.

@chevcast
Created July 27, 2023 15:43
Show Gist options
  • Save chevcast/49a4c6e435bcb6171db5157d04760d1d to your computer and use it in GitHub Desktop.
Save chevcast/49a4c6e435bcb6171db5157d04760d1d to your computer and use it in GitHub Desktop.
const axios = require("axios");
const dotenv = require("dotenv");
dotenv.config();
const baseUrl = "https://api.stackexchange.com/2.3";
const key = process.env.KEY;
const accessToken = process.env.ACCESS_TOKEN;
const myUserId = // your stack user ID
const targetUserId = // editor user ID;
const fetchUserRevisions = async (postIds) => {
const revisions = [];
for (const postId of postIds) {
const url = '${baseUrl}/posts/${postId}/revisions?key=${key}&access_token=${accessToken}&site=stackoverflow';
const { data } = await axios(url);
revisions.push(...data.items);
}
return revisions;
};
const main = async () => {
let hasMore = true;
let currentPage = 1;
let postIds = [];
while (hasMore) {
const url = `${baseUrl}/users/${myUserId}/posts?key=${key}&access_token=${accessToken}&site=stackoverflow&pagesize=100&page=${currentPage}`;
const { data } = await axios(url);
hasMore = data.has_more;
currentPage++;
postIds.push(...data.items.map((post) => post.post_id));
}
const userRevisions = await fetchUserRevisions(postIds);
const targetUserRevisions = userRevisions.filter(
(revision) => revision.user.user_id == targetUserId
);
targetUserRevisions.forEach((revision, index) => {
console.log(
`${index}. https://stackoverflow.com/posts/${revision.post_id}/revisions#${revision.revision_guid}`
);
});
};
main().catch(console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment