utils: deno fmt

This commit is contained in:
tree🌴 2024-01-31 01:57:12 +01:00
parent 2884a56045
commit 0cbbddd561
5 changed files with 106 additions and 89 deletions

View file

@ -1,23 +1,28 @@
import { parseFeed } from "https://deno.land/x/rss/mod.ts"; import { parseFeed } from "https://deno.land/x/rss/mod.ts";
import * as cheerio from "https://esm.sh/cheerio@1.0.0-rc.12"; import * as cheerio from "https://esm.sh/cheerio@1.0.0-rc.12";
const resp = await fetch("https://mirror.xyz/0x0f1F3DAf416B74DB3DE55Eb4D7513a80F4841073/feed/atom") const resp = await fetch(
const xml = await resp.text() "https://mirror.xyz/0x0f1F3DAf416B74DB3DE55Eb4D7513a80F4841073/feed/atom",
const feed = await parseFeed(xml) );
const xml = await resp.text();
const feed = await parseFeed(xml);
const articles = [] const articles = [];
for (const entry of feed.entries) { for (const entry of feed.entries) {
//console.log(entry) //console.log(entry)
const $ = cheerio.load(entry.content.value) const $ = cheerio.load(entry.content.value);
articles.push({ articles.push({
url: entry.id, url: entry.id,
title: entry.title.value, title: entry.title.value,
img: $("img").attr("src"), img: $("img").attr("src"),
date: entry.updated, date: entry.updated,
}) });
} }
//console.log(articles) //console.log(articles)
await Deno.writeTextFile("./src/articles.json", JSON.stringify(articles, null, 2)) await Deno.writeTextFile(
console.log(`File ./src/articles.json saved`) "./src/articles.json",
JSON.stringify(articles, null, 2),
);
console.log(`File ./src/articles.json saved`);

View file

@ -1,7 +1,6 @@
import "https://deno.land/std@0.206.0/dotenv/load.ts"; import "https://deno.land/std@0.206.0/dotenv/load.ts";
const contributorRepos = [ const contributorRepos = [
// main repos // main repos
"web3privacy/web3privacy", "web3privacy/web3privacy",
"web3privacy/data", "web3privacy/data",
@ -22,8 +21,7 @@ const contributorRepos = [
"web3privacy/grants", "web3privacy/grants",
"web3privacy/old-website", "web3privacy/old-website",
"web3privacy/web3privacy-app-old", "web3privacy/web3privacy-app-old",
];
]
function isBlacklisted(login) { function isBlacklisted(login) {
if (login.match(/\[bot\]$/)) { if (login.match(/\[bot\]$/)) {
@ -34,28 +32,34 @@ function isBlacklisted (login) {
async function getContributors() { async function getContributors() {
const output = []; const output = [];
for (const cr of contributorRepos) { for (const cr of contributorRepos) {
const response = await fetch(`https://api.github.com/repos/${cr}/contributors`, { const response = await fetch(
`https://api.github.com/repos/${cr}/contributors`,
{
//headers: { //headers: {
// "Authorization": `Token ${Deno.env.get('GITHUB_TOKEN')}` // "Authorization": `Token ${Deno.env.get('GITHUB_TOKEN')}`
//} //}
}); },
);
const arr = await response.json(); const arr = await response.json();
for (const item of arr) { for (const item of arr) {
if (isBlacklisted(item.login)) { if (isBlacklisted(item.login)) {
continue; continue;
} }
const found = output.find(i => i.login === item.login) const found = output.find((i) => i.login === item.login);
if (!found) { if (!found) {
output.push(item) output.push(item);
} else { } else {
found.contributions += item.contributions found.contributions += item.contributions;
} }
} }
} }
return output.sort((x, y) => y.contributions > x.contributions ? 1 : -1); return output.sort((x, y) => y.contributions > x.contributions ? 1 : -1);
} }
const contributors = await getContributors() const contributors = await getContributors();
await Deno.writeTextFile("./src/contributors.json", JSON.stringify(contributors, null, 2)) await Deno.writeTextFile(
console.log(`File ./src/contributors.json saved`) "./src/contributors.json",
JSON.stringify(contributors, null, 2),
);
console.log(`File ./src/contributors.json saved`);

View file

@ -1,4 +1,4 @@
const response = await fetch("https://data.web3privacy.info/") const response = await fetch("https://data.web3privacy.info/");
const data = await response.json() const data = await response.json();
await Deno.writeTextFile("./src/core.json", JSON.stringify(data, null, 2)) await Deno.writeTextFile("./src/core.json", JSON.stringify(data, null, 2));
console.log(`File ./src/core.json saved`) console.log(`File ./src/core.json saved`);

View file

@ -1,15 +1,18 @@
const resp = await fetch("https://explorer-data.web3privacy.info/"); const resp = await fetch("https://explorer-data.web3privacy.info/");
const data = await resp.json(); const data = await resp.json();
const respContribs = await fetch(`https://api.github.com/repos/web3privacy/explorer-data/contributors`) const respContribs = await fetch(
`https://api.github.com/repos/web3privacy/explorer-data/contributors`,
);
const respContribsData = await respContribs.json(); const respContribsData = await respContribs.json();
const explorer = { const explorer = {
projects: data.projects.length, projects: data.projects.length,
contributors: respContribsData.length, contributors: respContribsData.length,
} };
await Deno.writeTextFile("./src/explorer.json", JSON.stringify(explorer, null, 2)) await Deno.writeTextFile(
console.log(`File ./src/explorer.json saved`) "./src/explorer.json",
JSON.stringify(explorer, null, 2),
);
console.log(`File ./src/explorer.json saved`);

View file

@ -1,23 +1,28 @@
import { parseFeed } from "https://deno.land/x/rss/mod.ts"; import { parseFeed } from "https://deno.land/x/rss/mod.ts";
import * as cheerio from "https://esm.sh/cheerio@1.0.0-rc.12"; import * as cheerio from "https://esm.sh/cheerio@1.0.0-rc.12";
const resp = await fetch("https://www.youtube.com/feeds/videos.xml?channel_id=UCaO_vLpj164um5maEsCuEbw") const resp = await fetch(
const xml = await resp.text() "https://www.youtube.com/feeds/videos.xml?channel_id=UCaO_vLpj164um5maEsCuEbw",
const feed = await parseFeed(xml) );
const xml = await resp.text();
const feed = await parseFeed(xml);
const talks = [] const talks = [];
for (const entry of feed.entries) { for (const entry of feed.entries) {
console.log(entry) console.log(entry);
//const $ = cheerio.load(entry.content.value) //const $ = cheerio.load(entry.content.value)
talks.push({ talks.push({
url: entry.links[0].href, url: entry.links[0].href,
title: entry.title.value, title: entry.title.value,
img: entry["media:group"]["media:thumbnail"].url.replace("hqdefault", "maxresdefault"), img: entry["media:group"]["media:thumbnail"].url.replace(
"hqdefault",
"maxresdefault",
),
date: entry.published, date: entry.published,
}) });
} }
//console.log(articles) //console.log(articles)
await Deno.writeTextFile("./src/talks.json", JSON.stringify(talks, null, 2)) await Deno.writeTextFile("./src/talks.json", JSON.stringify(talks, null, 2));
console.log(`File ./src/talks.json saved`) console.log(`File ./src/talks.json saved`);