Skip to content

Instantly share code, notes, and snippets.

@kaiomagalhaes
Created October 8, 2025 19:14
Show Gist options
  • Select an option

  • Save kaiomagalhaes/76f62f15e67af10bd8e765d9665cdcbb to your computer and use it in GitHub Desktop.

Select an option

Save kaiomagalhaes/76f62f15e67af10bd8e765d9665cdcbb to your computer and use it in GitHub Desktop.
const site = "stackoverflow"
const tag = "python"
const response = await fetch(`https://api.stackexchange.com/2.3/questions?order=desc&sort=creation&site=${site}&tagged=${tag}&pagesize=100`)
const json = await response.json();
const items = json.items;
const group = {}
const months = new Set()
items.forEach((item) => {
const date = new Date(item.creation_date * 1000)
const month = date.getMonth()
const dateStr = date.toLocaleString()
const monthStr = month.toString().length < 2 ? `0${month}` : month.toString()
const yearStr = dateStr.substring(5,9)
const monthYear = `${monthStr}-${yearStr}`
const currentGroup = group[monthYear]
if (currentGroup) {
currentGroup.push(item)
} else {
group[monthYear] = [item]
}
months.add(monthYear)
})
console.log(months.values())
const data = []
months.values().forEach((month) => {
const items = group[month]
let totalLength = 0
const uniqAskers = {}
items.forEach((item) => {
totalLength = totalLength + item.title.length;
const asker = item.owner;
if (uniqAskers[asker.user_id]) {
// augment the values of the uniqAskers here
} else {
uniqAskers[asker.user_id] = {
name: asker.display_name || "not given",
question_count: 1
}
}
})
const avgTitleLength = totalLength / items.length
const dataObj = {
month: month,
question_count: items.length,
average_title_length: avgTitleLength,
uniq_askers: Object.keys(uniqAskers).length,
askers: Object.values(uniqAskers)
}
data.push(dataObj)
})
console.log(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment