Created
May 28, 2023 11:10
-
-
Save double-beep/a795d2c5b944a5e53564b63c06d0466d to your computer and use it in GitHub Desktop.
Fetches old suggested edits
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const textify = id => `https://stackoverflow.com/suggested-edits/${id}`; | |
const url = new URL('https://api.stackexchange.com/2.3/suggested-edits'); | |
const params = { | |
key: 'U4DMV*8nvpm3EOpvf69Rxw((', // SE key | |
site: 'stackoverflow', | |
pagesize: '100', | |
order: 'desc', | |
sort: 'creation', | |
filter: '!b)GQTHKTSeuf2h' | |
}; | |
Object | |
.entries(params) | |
.forEach(([key, value]) => url.searchParams.set(key, value)); | |
async function fetchApi(page) { | |
// increase page number: | |
url.searchParams.set('page', page); | |
const request = await fetch(url.toString()); | |
const response = await request.json(); | |
// address backoff | |
if (response.backoff) { | |
// backoff is time to wait *in seconds* | |
const timeToWait = Number(json.backoff) * 1000; | |
await new Promise(resolve => setTimeout(resolve, timeToWait)); | |
} | |
return response | |
.items | |
.filter(item => !item?.rejection_date // not rejected | |
&& !item?.approval_date // or approved | |
&& item.creation_date <= Date.now() / 1000 - 86400 * 3 // at least three days old | |
); | |
} | |
/* let */ edits = []; | |
for (let page = 1; page <= 60; page++) { | |
const result = await fetchApi(page); | |
edits.push(result); | |
} | |
edits = edits.flat(Infinity); | |
// log result | |
edits.forEach(({ suggested_edit_id: id }) => console.log(textify(id))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment