-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitter-post.js
33 lines (29 loc) · 989 Bytes
/
twitter-post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const Twitter = require('twitter');
// Replace YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET, YOUR_ACCESS_TOKEN_KEY, and YOUR_ACCESS_TOKEN_SECRET
// with your actual Twitter API keys and tokens
const client = new Twitter({
consumer_key: 'YOUR_CONSUMER_KEY',
consumer_secret: 'YOUR_CONSUMER_SECRET',
access_token_key: 'YOUR_ACCESS_TOKEN_KEY',
access_token_secret: 'YOUR_ACCESS_TOKEN_SECRET'
});
// This is the sales data that you want to send updates for
const sales = {
'Product A': 100,
'Product B': 50,
'Product C': 25
};
// Send the updates to Twitter
function sendUpdates() {
let message = 'Sales updates:\n';
for (const product in sales) {
message += `- ${product}: ${sales[product]} units sold\n`;
}
client.post('statuses/update', { status: message }, function (error, tweet, response) {
if (error) {
console.error(error);
}
});
}
// Send the updates every hour
setInterval(sendUpdates, 3600 * 1000);