Skip to content

Commit cb0a3ad

Browse files
committed
latest resources
1 parent c0dcbb4 commit cb0a3ad

File tree

5 files changed

+134
-3
lines changed

5 files changed

+134
-3
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Tweet Lastest Resources
2+
3+
on:
4+
schedule:
5+
- cron: "30 14 * * 3"
6+
workflow_dispatch:
7+
8+
jobs:
9+
build:
10+
name: Lastest Resources
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout Repo
14+
uses: actions/checkout@master
15+
- name: Use Node.js
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: '16.x'
19+
- name: Install Dependencies
20+
run: yarn install
21+
- name: Get Lastest Resources
22+
run: yarn latest:resources

.github/workflows/latest.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: Lastest Resources
1+
name: Show Lastest
22

33
on:
44
workflow_dispatch:
55

66
jobs:
77
build:
8-
name: Lastest Resources
8+
name: Show Lastest
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout Repo
@@ -16,5 +16,5 @@ jobs:
1616
node-version: '16.x'
1717
- name: Install Dependencies
1818
run: yarn install
19-
- name: Get Lastest Resources
19+
- name: Show Lastest Resources
2020
run: yarn latest

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ Variables:
6464
AIRTABLE_API_BASE=
6565
```
6666

67+
## Twitter Schedule
68+
useWeb3 Schedules
69+
70+
- Random daily resource: "30 15 * * *" - daily
71+
- Most popular (categories): "0 15 * * 0" - sunday
72+
- GM: "0 10 * * 1" - monday
73+
- Random tip: "30 16 * * 2" - tuesday
74+
- Latest resources: "30 14 * * 3" - wednesday
75+
- Latest issues: "0 13 * * 4" - thursday
76+
- Coolest thing you did last week: "0 14 * * 5" - friday
77+
- Most popular (resources): "0 15 * * 6" - saturday
78+
6779
# Powered by
6880

6981
[![Powered by Vercel](https://www.datocms-assets.com/31049/1618983297-powered-by-vercel.svg "Powered by Vercel")](https://vercel.com/?utm_source=useWeb3&utm_campaign=oss)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"lint": "next lint --fix",
1010
"prettier": "prettier --write ./src/**/*.{ts,tsx,scss}",
1111
"latest": "ts-node src/tools/latest",
12+
"latest:resources": "ts-node src/tools/latest-resources",
1213
"latest:issues": "ts-node src/tools/latest-issues",
1314
"twitter:gm": "ts-node src/tools/twitter-gm",
1415
"twitter:last-week": "ts-node src/tools/twitter-last-week",

src/tools/latest-resources.ts

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import * as dotenv from 'dotenv'
2+
import moment from 'moment'
3+
import { MarkdownContentService } from '../services/content'
4+
const Twit = require('twit')
5+
6+
dotenv.config()
7+
8+
console.log('Get Latest resources')
9+
run()
10+
11+
async function run() {
12+
const since = moment.utc().subtract(7, 'day')
13+
14+
const service = new MarkdownContentService()
15+
const categories = await service.GetCategories()
16+
const items = await service.GetItems()
17+
const recent = items.filter((i) => moment(i.dateAdded).isAfter(since))
18+
19+
console.log('New Resources since', since.toISOString(), recent.length)
20+
console.log('')
21+
22+
// If no items - don't post
23+
if (recent.length === 0) return
24+
25+
const twitterClient = new Twit({
26+
consumer_key: process.env.TWITTER_CONSUMER_KEY,
27+
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
28+
access_token: process.env.TWITTER_ACCESS_TOKEN,
29+
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET,
30+
})
31+
32+
// If just 1 item, but as single tweet
33+
if (recent.length === 1) {
34+
const item = recent[0]
35+
const category = categories.find((i) => i.id === item.category.id)
36+
37+
const text = `NEW Resource added ✨\n\n
38+
${category?.emoji} ${item.title}
39+
by ${item.authors.join(' ')}
40+
41+
${item.url}`
42+
43+
const response = await twitterClient.post('statuses/update', { status: text })
44+
if (response.err) {
45+
console.log('Unable to post Twitter update..')
46+
console.error(response.err)
47+
}
48+
if (response.data) {
49+
console.log(`https://twitter.com/useWeb3/status/${response.data.id_str}`)
50+
}
51+
52+
return
53+
}
54+
55+
// If multiple items. Sent thread, with each resource as separate Tweet
56+
57+
// 1st tweet
58+
let text = `Recently added resources ✨\n\n`
59+
text += `x/${recent.length} 👇`
60+
61+
let replyTo = ''
62+
const response = await twitterClient.post('statuses/update', { status: text })
63+
if (response.err) {
64+
console.log('Unable to post Twitter update..')
65+
console.error(response.err)
66+
}
67+
if (response.data) {
68+
replyTo = response.data.id_str
69+
}
70+
71+
// Resource tweets
72+
for (let i = 0; i < recent.length; i++) {
73+
const item = recent[i]
74+
const category = categories.find((i) => i.id === item.category.id)
75+
76+
const text = `${category?.emoji} ${item.title}
77+
by ${item.authors.join(' ')}
78+
79+
${i + 1}/${recent.length}
80+
81+
${item.url}`
82+
83+
const response = await twitterClient.post('statuses/update', {
84+
status: text,
85+
in_reply_to_status_id: replyTo,
86+
auto_populate_reply_metadata: true,
87+
})
88+
if (response.err) {
89+
console.log('Unable to post Twitter update..')
90+
console.error(response.err)
91+
}
92+
if (response.data) {
93+
replyTo = response.data.id_str
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)