-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
45 lines (37 loc) · 1.6 KB
/
index.ts
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
import dotenv from 'dotenv'
import puppeteer from "puppeteer";
import { format } from "date-fns";
import { TwitterApi } from 'twitter-api-v2';
dotenv.config()
const client = new TwitterApi({
appKey: process.env.TWITTER_CONSUMER_KEY as string,
appSecret: process.env.TWITTER_CONSUMER_SECRET as string,
accessToken: process.env.TWITTER_ACCESS_TOKEN_KEY as string,
accessSecret: process.env.TWITTER_ACCESS_TOKEN_SECRET as string,
});
async function grabGithubData(): Promise<string> {
const browser = await puppeteer.launch({ executablePath: "chromium" });
// const browser = await puppeteer.launch();
const page = await browser.newPage();
const currentYear = format(new Date(), "yyyy");
await page.goto(
`https://github.com/users/ronnapatp/contributions?from=${currentYear}-01-01`
);
let contribs = await page.$$eval("[data-count]", (val) =>
val.reduce((acc, val) => acc + +(val.getAttribute("data-count")!) , 0)
);
await browser.close();
return `${currentYear} Github Contributions : ${contribs} 👋🏻`;
}
async function main() {
const d = new Date();
let nextyear = d.getFullYear() + 1;
let countDownDate = new Date(`Jan 1, ${nextyear}`).getTime();
let now = new Date().getTime();
let distance = countDownDate - now;
let newyears = Math.floor(distance / (1000 * 60 * 60 * 24));
const githubData = await grabGithubData();
await client.v1.updateAccountProfile({ name: 'ronnapatp 🇺🇦', url: 'https://ronnapat.com/', description: `#SlavaUkraine 🇺🇦 | Politics Enthusiast`, location: 'Thailand' })
console.log('Done!')
}
main().catch(err=> console.log(err))