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
import { fetch } from "https://esm.town/v/std/fetch";
type RepoData = {
date: string;
rank: number;
full_name: string;
description: string;
language: string;
stars: number;
forks: number;
stars_recent: number;
};
export const Github_ScrapeTrendingRepos = async (
timeframe: string,
): Promise<RepoData[]> => {
const { cheerioJsonMapper: cjm } = await import("npm:cheerio-json-mapper");
const res = await fetch(`https://github.com/trending?since=${timeframe}`);
const html = await res.text();
const template = [
{
$: "article",
full_name: " > h2 > a | attr:href",
description: " > p",
language: " span[itemprop]",
stars: " > .f6 > a:first",
forks: " > .f6 > a:last",
stars_recent: " > .f6 > span:last",
},
];
const data = await cjm(html, template);
const date = new Date();
return data.map((d, i) => ({
date: date.toISOString(),
rank: i + 1,
full_name: d.full_name.slice(1),
description: d.description,
language: d.language,
stars: +d.stars.replace(",", ""),
forks: +d.forks.replace(",", ""),
stars_recent: +d.stars_recent.split(" ")[0].replace(",", ""),
}));
};
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.