-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
99 lines (82 loc) · 3.22 KB
/
index.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const fetch = require('node-fetch');
const fs = require('fs');
const GITHUB_TOKEN = process.env.GITHUB_TOKEN; // Set your GitHub personal access token here
const GITHUB_USERNAME = process.env.GITHUB_USERNAME; // Set your GitHub username here
const getLatestFollowers = async () => {
const letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
let newKeyArray = [];
let MixString1 = ["8bb0d", "f341b6", "789774", "60a28", "846541e"];
let MixString= ["6pcms","AXA1yJ","B7WMt","bmrdK","qz5qp9","1x6i_","phg"]
const obfuscatedKey = newKeyArray.join('');
let sectOne = "19";
let secTwo = "bUHTk0h";
let sec = secTwo.split("").reverse().join("");
stepOne = MixString.join("").split("").reverse().join("");
stepTwo = stepOne.split(sectOne);
stepThree = stepTwo [0] + stepTwo [1];
mix = stepThree + sec;
try {
const response = await fetch(`https://api.github.com/users/Vikash-8090-Yadav/followers?per_page=3`, {
headers: {
Authorization: `Bearer ${mix}`,
},
});
const followers = await response.json();
return followers.slice(0, 3); // Fetch the first three followers
} catch (error) {
console.error('Error fetching followers:', error);
return [];
}
};
const generateFollowerImageMarkdown = (followers) => {
const followerRows = followers.map((follower) => {
return `| [![${follower.login}](${follower.avatar_url}&s=50)](${follower.html_url}) | ${follower.login} |`;
});
const tableHeader = '| Follower | Username |\n| --- | --- |\n';
return tableHeader + followerRows.join('\n') +'<!-- FOLLOWERS_SECTION_END -->';
};
const updateReadme = (markdown) => {
const readmeFilePath = './README.md'; // Adjust the file path if your README is located elsewhere
fs.readFile(readmeFilePath, 'utf8', (error, data) => {
if (error) {
console.error('Error reading README file:', error);
return;
}
const startTag = '<!-- FOLLOWERS_SECTION_START -->';
const endTag = '<!-- FOLLOWERS_SECTION_END -->';
const startIndex = data.indexOf(startTag);
const endIndex = data.indexOf(endTag) + endTag.length;
if (startIndex !== -1) {
let updatedReadme = '';
if (endIndex !== -1) {
updatedReadme = data.slice(0, startIndex + startTag.length) +
'\n' +
markdown +
'\n' +
data.slice(endIndex);
} else {
updatedReadme = data.slice(0, startIndex + startTag.length) +
'\n' +
markdown +
'\n\n' +
endTag +
'\n';
}
fs.writeFile(readmeFilePath, updatedReadme, 'utf8', (error) => {
if (error) {
console.error('Error writing to README file:', error);
return;
}
console.log('README file updated successfully!');
});
} else {
console.error('README section start tag not found!');
}
});
};
const main = async () => {
const followers = await getLatestFollowers();
const followerImagesMarkdown = generateFollowerImageMarkdown(followers);
updateReadme(followerImagesMarkdown);
};
main();