Skip to content

Instantly share code, notes, and snippets.

@samlaf
Created December 6, 2021 16:04
Show Gist options
  • Save samlaf/8965461492d37b48b11b5e3338ef9fed to your computer and use it in GitHub Desktop.
Save samlaf/8965461492d37b48b11b5e3338ef9fed to your computer and use it in GitHub Desktop.
Plot the number of eips published per year
import { Layout, plot, Plot } from 'nodeplotlib';
import { readFileSync } from 'fs';
(async () => {
let readVal = readFileSync('eips.json', {
encoding: "utf-8"
});
const eips = JSON.parse(readVal);
readVal = readFileSync('dates.json', {encoding: "utf-8"})
const dates = JSON.parse(readVal);
const dateCounts: Record<number, number> = {}
for (const date of dates) {
dateCounts[date] = dateCounts[date] ? dateCounts[date] + 1 : 1;
}
var trace: Plot = {
x:Object.keys(dateCounts),
y: Object.values(dateCounts) as any[],
type: 'bar'
}
var layout: Layout = {
"title": "Number of EIPs Published per Year",
};
plot( [trace], layout);
})();
import jsdom from "jsdom";
const { JSDOM } = jsdom;
import axios from 'axios';
import { writeFile } from 'fs';
// this file scrapes and writes eip nums and years to files
// eips.json contains [1, 2, 5, ...] (eips)
// dates.json contains [2015, 2015, 2016, ... ] (year of each eip)
const baseURL = 'https://eips.ethereum.org';
async function getEIPdate(path: any) {
// returns {eip: year} dictionary
const eipHtml = await axios.get(baseURL + path)
const { document } = (new JSDOM(eipHtml.data as string)).window;
const table = document.getElementsByClassName("home")[0].children[2];
const rows = [...table.children[0].children]
const createdRow = rows.filter((tr) => tr.children[0].innerHTML == "Created")[0]
const date = new Date(createdRow.children[1].innerHTML);
return date.getFullYear();
}
(async () => {
const html = await axios.get(baseURL + '/all')
const { document } = (new JSDOM(html.data as string)).window;
let eipnumHTMLCollection = document.getElementsByClassName("eipnum");
let eipnumElems = [...eipnumHTMLCollection];
let eipnumAnchors = eipnumElems.map((item) => item.children[0])
.filter((item) => item !== undefined)
const paths = eipnumAnchors.map((item) => (item as any).href)
const eipnums = eipnumAnchors.map((item) => Number(item.innerHTML))
writeFile(
'./eips.json',
JSON.stringify(eipnums),
function(err: any) {
if (err) {
console.error('oops');
}
}
);
const dates = await Promise.all(paths.map((path) => getEIPdate(path)))
writeFile(
'./dates.json',
JSON.stringify(dates),
function(err: any) {
if (err) {
console.error('oops');
}
}
);
console.log("Finished writing");
})()
@samlaf
Copy link
Author

samlaf commented Dec 6, 2021

Run scrape.ts first and then plot.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment