Skip to content

Instantly share code, notes, and snippets.

@yakkomajuri
Created November 18, 2021 12:38
Show Gist options
  • Save yakkomajuri/90a16f97ca27e557e385a91f4ed12b04 to your computer and use it in GitHub Desktop.
Save yakkomajuri/90a16f97ca27e557e385a91f4ed12b04 to your computer and use it in GitHub Desktop.
export async function runEveryMinute({ config, cache }) {
const res = await fetch('https://api.producthunt.com/v2/api/graphql', {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${config.token}`
},
body: JSON.stringify({
"operationName": "GetAllTheData",
"variables": {},
"query": "query todayPosts { posts { edges { node { id name tagline votesCount } } } }" }
),
method: 'POST'
})
const resJson = await res.json()
const products = resJson.data.posts.edges
for (let i = 0; i < products.length; ++i) {
const product = products[i].node
if (product.name === 'PostHog') {
await posthog.capture('producthunt_update', { position: i+1, votes: product.votesCount })
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment