-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunning.js
43 lines (34 loc) · 1.72 KB
/
running.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
import { Octokit } from "@octokit/core";
import fetch from 'node-fetch';
const octokit = new Octokit({
auth: '',
request: {fetch,},
});
async function commitViaAPI() {
// Get references
const readme = await octokit.request("GET /repos/lvhoaa/lvhoaa/contents/README.md", {
ref: "main",
});
// Get current time
const currentDate = new Date();
const options = { timeZone: 'America/New_York', timeStyle: 'medium' };
const currentTimeInEST = currentDate.toLocaleString('en-US', options);
const currentHour = currentTimeInEST.split(":")[0]
const currentMinute = currentTimeInEST.split(":")[1]
const currentMeridiem = currentTimeInEST.slice(-2);
const currentTime = currentHour+":"+currentMinute+" "+currentMeridiem
// Update file & commit
const updatedContent = "### Hi there, I'm Hoa La 👋 \n\n 👨💻 3 key facts about me: \n - 🌱 I’m studying CS @ UMass Amherst, hoping to become a full-stack developer \n - 👨💼 Having interned at Abbott and Kyons with software engineering role in the past \n - 💼 Having published a computer science paper in a peer-reviewed journal \n\n 🕒 My current time is "+ currentTime+ " (updated via API) \n\n 📫 How to reach me: [email protected]"
try{
const result = await octokit.request("PUT /repos/lvhoaa/lvhoaa/contents/README.md", {
message: "Update README.md using API",
content: Buffer.from(updatedContent).toString("base64"),
sha: readme.data.sha,
branch: "main",
});
} catch(error){
console.log(error);
}
console.log("running"+currentTime);
}
const running = setInterval(commitViaAPI,60000);