add top meme and fact to newsletter script
This commit is contained in:
parent
d91d69bd42
commit
e3b81b7746
@ -31,13 +31,51 @@ const client = new ApolloClient({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const abbrNum = n => {
|
const abbrNum = n => {
|
||||||
if (n < 1e4) return n
|
if (n < 1e3) return n
|
||||||
if (n >= 1e4 && n < 1e6) return +(n / 1e3).toFixed(1) + 'k'
|
if (n >= 1e3 && n < 1e6) return +(n / 1e3).toFixed(1) + 'k'
|
||||||
if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + 'm'
|
if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + 'm'
|
||||||
if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + 'b'
|
if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + 'b'
|
||||||
if (n >= 1e12) return +(n / 1e12).toFixed(1) + 't'
|
if (n >= 1e12) return +(n / 1e12).toFixed(1) + 't'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function bountyWinner (q) {
|
||||||
|
const BOUNTY = gql`
|
||||||
|
query Search($q: String, $sort: String, $what: String, $when: String) {
|
||||||
|
search(q: $q, sort: $sort, what: $what, when: $when) {
|
||||||
|
items {
|
||||||
|
id
|
||||||
|
bountyPaidTo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
const WINNER = gql`
|
||||||
|
query Item($id: ID!) {
|
||||||
|
item(id: $id) {
|
||||||
|
text
|
||||||
|
sats
|
||||||
|
imgproxyUrls
|
||||||
|
user {
|
||||||
|
name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`
|
||||||
|
|
||||||
|
const bounty = await client.query({
|
||||||
|
query: BOUNTY,
|
||||||
|
variables: { q: `${q} nym:sn`, sort: 'recent', what: 'posts', when: 'week' }
|
||||||
|
})
|
||||||
|
|
||||||
|
const item = await client.query({
|
||||||
|
query: WINNER,
|
||||||
|
variables: { id: bounty.data.search.items[0].bountyPaidTo[0] }
|
||||||
|
})
|
||||||
|
|
||||||
|
const winner = { ...item.data.item, image: Object.values(item.data.item.imgproxyUrls)[0]?.['640w'] }
|
||||||
|
|
||||||
|
return { bounty: bounty.data.search.items[0].id, winner }
|
||||||
|
}
|
||||||
|
|
||||||
async function main () {
|
async function main () {
|
||||||
const top = await client.query({
|
const top = await client.query({
|
||||||
query: ITEMS,
|
query: ITEMS,
|
||||||
@ -54,6 +92,9 @@ async function main () {
|
|||||||
variables: { sub: 'jobs' }
|
variables: { sub: 'jobs' }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const topMeme = await bountyWinner('monday meme')
|
||||||
|
const topFact = await bountyWinner('fun fact')
|
||||||
|
|
||||||
process.stdout.write(
|
process.stdout.write(
|
||||||
`Happy Sat-urday Stackers,
|
`Happy Sat-urday Stackers,
|
||||||
|
|
||||||
@ -63,7 +104,7 @@ Have a great weekend!
|
|||||||
${top.data.items.items.slice(0, 10).map((item, i) =>
|
${top.data.items.items.slice(0, 10).map((item, i) =>
|
||||||
`${i + 1}. [@${item.user.name}](https://stacker.news/${item.user.name}) [${item.title}](https://stacker.news/items/${item.id})
|
`${i + 1}. [@${item.user.name}](https://stacker.news/${item.user.name}) [${item.title}](https://stacker.news/items/${item.id})
|
||||||
- [${item.title}](https://stacker.news/items/${item.id})
|
- [${item.title}](https://stacker.news/items/${item.id})
|
||||||
- ${abbrNum(item.sats)} sats${item.boost ? ` \\ ${abbrNum(item.boost)} boost` : ''} \\ ${item.ncomments} comments\n`).join('')}
|
- ${abbrNum(item.sats)} sats${item.boost ? ` \\ ${abbrNum(item.boost)} boost` : ''} \\ ${item.ncomments} comments \\ [@${item.user.name}](https://stacker.news/${item.user.name})\n`).join('')}
|
||||||
|
|
||||||
##### Don't miss
|
##### Don't miss
|
||||||
${top.data.items.items.map((item, i) =>
|
${top.data.items.items.map((item, i) =>
|
||||||
@ -75,6 +116,16 @@ ${meta.data.items.items.slice(0, 10).map((item, i) =>
|
|||||||
|
|
||||||
[**all of this week's top posts**](https://stacker.news/top/posts/week)
|
[**all of this week's top posts**](https://stacker.news/top/posts/week)
|
||||||
|
|
||||||
|
##### Top Monday meme \\ ${abbrNum(topMeme.winner.sats)} sats \\ [@${topMeme.winner.user.name}](https://stacker.news/${topMeme.winner.user.name})
|
||||||
|
![](${topMeme.winner.image})
|
||||||
|
|
||||||
|
[**all monday memes**](https://stacker.news/items/${topMeme.bounty})
|
||||||
|
|
||||||
|
##### Top Friday fun fact \\ ${abbrNum(topFact.winner.sats)} sats \\ [@${topFact.winner.user.name}](https://stacker.news/${topFact.winner.user.name})
|
||||||
|
${topFact.winner.text}
|
||||||
|
|
||||||
|
[**all friday fun facts**](https://stacker.news/items/${topFact.bounty})
|
||||||
|
|
||||||
##### Promoted jobs
|
##### Promoted jobs
|
||||||
${jobs.data.items.items.filter(i => i.maxBid > 0 && i.status === 'ACTIVE').slice(0, 5).map((item, i) =>
|
${jobs.data.items.items.filter(i => i.maxBid > 0 && i.status === 'ACTIVE').slice(0, 5).map((item, i) =>
|
||||||
`${i + 1}. [${item.title.trim()} \\ ${item.company} \\ ${item.location}${item.remote ? ' or Remote' : ''}](https://stacker.news/items/${item.id})\n`).join('')}
|
`${i + 1}. [${item.title.trim()} \\ ${item.company} \\ ${item.location}${item.remote ? ' or Remote' : ''}](https://stacker.news/items/${item.id})\n`).join('')}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user