-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet.js
75 lines (69 loc) · 2.18 KB
/
tweet.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require("dotenv").config({ path: __dirname + "/.env.dailygithub" });
const { TwitterClient } = require("./client.js");
import {
getMostTrendingRepoWeekly,
getMostTrendingRepoDaily,
} from "./github.js";
class TwitterBot {
constructor() {
}
async weeklyTweet() {
try {
const repos = await getMostTrendingRepoWeekly();
for (const repo of repos) {
const repo_url = repo.html_url;
const repo_description = repo.description;
const repo_language = repo.language;
const repo_stars = repo.stargazers_count;
const repo_forks = repo.forks_count;
if (
repo_url &&
repo_description &&
repo_language &&
repo_stars &&
repo_forks &&
repo_description <= 60
) {
await this.twitterClient.v2.tweet({
text: `🌟 The most starred repo of the week!\n🔗 ${repo_url}\n📝 Description: ${repo_description}\n🔠 Language: ${repo_language}\n⭐ Stars: ${repo_stars}\n🍴 Forks: ${repo_forks}`,
});
break; // Tweet only one repo
}
}
} catch (e) {
console.log(e);
}
}
async oneOfTheMostDaily() {
try {
const repos = await getMostTrendingRepoDaily();
for (const repo of repos) {
const repo_url = repo.html_url;
const repo_description = repo.description;
const repo_language = repo.language;
const repo_stars = repo.stargazers_count;
const repo_forks = repo.forks_count;
if (
repo_url &&
repo_description &&
repo_language &&
repo_stars &&
repo_forks &&
repo_description <= 60
) {
console.log(repos.indexOf(repo));
await this.twitterClient.v2.tweet({
text: `🌟 One of the most starred repo of the day!\n🔗 ${repo_url}\n📝 Description: ${repo_description}\n🔠 Language: ${repo_language}\n⭐ Stars: ${repo_stars}\n🍴 Forks: ${repo_forks}`,
});
break; // Tweet only one repo
}
}
} catch (e) {
console.log(e);
}
}
}
const bot = new TwitterBot();
bot.weeklyTweet();
bot.oneOfTheMostDaily();
oneOfTheMostDaily();