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
43
44
45
46
47
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
/**
Receive daily emails of reported congress trades by scheduling a call to
@claytn.fetchCongressTradeReports((reports) => console.email(reports))
*/
export async function fetchCongressTradeReports(callback) {
const res = await fetchJSON(
"https://bff.capitoltrades.com/trades?sortBy=-pubDate"
);
const trades = res.data;
function isToday(d) {
const now = new Date();
return (
d.getFullYear() === now.getFullYear() &&
d.getMonth() === now.getMonth() &&
d.getDate() === now.getDate()
);
}
const stockTradesReportedToday = trades.filter((trade) => {
const tradePublishDate = new Date(trade.pubDate);
return isToday(tradePublishDate) && trade.asset.assetType === "stock";
});
const reportings = stockTradesReportedToday
.map((trade) => {
return `
Politician: ${
trade.politician.firstName + " " + trade.politician.lastName
}
Party: ${trade.politician.party}
Asset: ${trade.asset.assetTicker})
Transaction Type: ${trade.txType}
Transaction Date: ${trade.txDate}
Esimated value: ~\$${trade.value}
`;
})
.join("\n\n");
callback(reportings);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.