1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { Options, Parser as CsvParser } from "npm:json2csv";
export default async function(req: Request): Promise<Response> {
const blockFeesResp = await fetch("https://mempool.space/api/v1/mining/blocks/fees/3y");
const blockFees = await blockFeesResp.json();
const dateAndDifficulties = blockFees.map(b => ({
dateTime: new Date(b.timestamp * 1000).toUTCString(),
avgFees: b.avgFees,
avgBlockHeight: b.avgHeight,
usd: b.USD,
}));
const csvParser = new CsvParser();
const csv = csvParser.parse(dateAndDifficulties);
return new Response(csv);
}