-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetchTrending.ts
45 lines (38 loc) · 1.54 KB
/
fetchTrending.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 fs from 'fs';
import path from 'path';
import axios from 'axios';
interface Repo {
name: string;
url: string;
author: string;
description: string;
language: string;
languageColor: string;
stars: number;
forks: number;
builtBy: { username: string; href: string }[];
currentPeriodStars: number;
}
async function fetchTrendingRepos() {
try {
const response = await axios.get<Repo[]>('https://github-api.nines.world/trending');
const repos = response.data;
let markdownContent = '## Trending Repositories\n\n';
markdownContent += '| Repository | Description | Language | Stars | Forks | Built By | Current Period Stars |\n';
markdownContent += '|------------|-------------|----------|-------|-------|----------|---------------------|\n';
repos.forEach(repo => {
markdownContent += `| [${repo.author}/${repo.name}](${repo.url}) | ${repo.description} | ${repo.language} | ${repo.stars} | ${repo.forks} | ${repo.builtBy.map(builder => `[${builder.username}](${builder.href})`).join(', ')} | ${repo.currentPeriodStars} |\n`;
});
const date = new Date().toISOString().split('T')[0];
const directory = path.join(__dirname, 'trending');
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory);
}
const fileName = path.join(directory, `trending-${date}.md`);
fs.writeFileSync(fileName, markdownContent);
console.log(`Markdown file ${fileName} created successfully.`);
} catch (error) {
console.error('Error fetching trending repositories:', error);
}
}
fetchTrendingRepos();