Benjamin Lannon

Benjamin Lannon

view-github-trending-repos

by Benjamin Lannon

Pulls down trending repos from github and save to database

// Menu: GitHub Trending
// Description: Show today's Trending GitHub Repos for various languages
const trendingDB = db("github-trending");
const langs = ["rust", "javascript", "typescript", "go", "python", "ruby"];
for (const lang of langs) {
onTab(lang, async () => {
const repo = await arg("Select a repo to open it", trendingDB.get(lang));
exec(`open ${repo}`);
});
}
// Description: Pulls down trending repos from github and save to database
// Schedule: 0 * * * *
// Exclude: true
/** @type typeof import('playwright') */
const playwright = await npm("playwright");
let dbDefaults = {};
const langs = ["rust", "javascript", "typescript", "go", "python", "ruby"];
for (const lang of langs) {
dbDefaults[lang] = [];
}
const trendingDB = db("github-trending", dbDefaults);
const browser = await playwright.chromium.launch();
for (const lang of langs) {
const context = await browser.newContext();
const page = await context.newPage();
await page.goto(`https://github.com/trending/${lang}`);
const repos = await page.evaluate(() => {
const repos = document.querySelectorAll(".Box-row");
const results = [];
for (let repo of repos) {
const repoName = repo.querySelector("h1 a").getAttribute("href").slice(1);
let description = repo.querySelector("p")?.textContent.trim();
const starCount = repo
.querySelector("div span.d-inline-block.float-sm-right")
?.textContent.trim();
if (!description) {
description = starCount;
} else {
description = `${starCount} | ${description}`;
}
results.push({
name: repoName,
value: `https://github.com/${repoName}`,
description,
});
}
return results;
});
trendingDB.set(lang, repos).write();
}
await browser.close();

View all supported versions of NodeJS

// Menu: Available Node versions
// Description: View all supported versions of NodeJS
// Author: Benjamin Lannon
// Twitter: @lannonbr
let resp = await get(
"https://raw.githubusercontent.com/nodejs/Release/main/schedule.json"
);
const data = Object.entries(resp.data);
/** @type typeof import('dayjs') */
let dayjs = await npm("dayjs");
let opts = [];
for (let [version, info] of data) {
let isSupported =
dayjs(info.start).diff(dayjs(), "days") < 0 &&
dayjs(info.end).diff(dayjs(), "days") > 0;
if (isSupported) {
opts.push({
name: `Node ${version}`,
description: `Maintainence ends on ${dayjs(info.end).format(
"MMMM DD, YYYY"
)}`,
endDate: info.end,
});
}
}
opts = opts.sort((a, b) => {
return dayjs(a.endDate).unix() - dayjs(b.endDate).unix();
});
await arg("These versions of NodeJS are currently maintained", opts);

View this week's tasks from Todoist

// Menu: Todoist Tasks
// Description: View this week's tasks from Todoist
// Author: Benjamin Lannon
// Twitter: @lannonbr
/** @type typeof import('todoist') */
const todoistPackage = await npm("todoist");
/** @type typeof import('dayjs') */
const dayjs = await npm("dayjs");
// API Token can be found here: https://todoist.com/prefs/integrations
const token = await env("TODOIST_TOKEN");
const client = todoistPackage.v8(token);
await client.sync();
let items = client.items.get();
items = items.filter((item) => {
let dueDate = dayjs(item.due.date);
return dueDate.diff(dayjs(), "day") <= 7;
});
await arg(
"View this week's tasks",
items.map((item) => {
return {
name: item.content,
description: `Due: ${item.due.date}`,
};
})
);