Created
November 18, 2021 12:38
-
-
Save yakkomajuri/90a16f97ca27e557e385a91f4ed12b04 to your computer and use it in GitHub Desktop.
This file contains 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
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