Avatar

claytn

7 public vals
Joined January 12, 2023
1
2
3
4
import { fetch } from "https://esm.town/v/std/fetch";
export let replitList = (REPLIT_DB_URL, prefix) =>
fetch(`${REPLIT_DB_URL}?prefix=${encodeURIComponent(prefix)}`);
1
2
3
4
import { fetch } from "https://esm.town/v/std/fetch";
export let replitDelete = (REPLIT_DB_URL, key) =>
fetch(`${REPLIT_DB_URL}/${key}`, { method: "DELETE" });
1
2
3
4
5
6
7
import { fetch } from "https://esm.town/v/std/fetch";
export let replitSet = (REPLIT_DB_URL, key, value) =>
fetch(`${REPLIT_DB_URL}/${key}=${encodeURIComponent(value)}`, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
1
2
3
import { fetch } from "https://esm.town/v/std/fetch";
export let replitGet = (REPLIT_DB_URL, key) => fetch(`${REPLIT_DB_URL}/${key}`);
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
import { fetch } from "https://esm.town/v/std/fetch";
/**
NOTE:
THIS CLIENT DOES NOT WORK AS EXPECTED. ALL VALS IN VAL TOWN
ARE JSON.stringify-ied SO RETURNED CLOSURES AREN'T SUPPORTED
USE THE INDIVIDUAL FUNCTIONS INSTEAD:
@claytn.replitGet
@claytn.replitSet
@claytn.replitDelete
@claytn.replitList
*/
/** Database client for replit's key-value store */
export function createReplitDBClient(REPLIT_DB_URL) {
return {
get: (key) => {
return fetch(`${REPLIT_DB_URL}/${key}`);
},
set: (key, value) => {
return fetch(`${REPLIT_DB_URL}/${key}=${encodeURIComponent(value)}`, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
});
},
delete: (key) => {
return fetch(`${REPLIT_DB_URL}/${key}`, { method: "DELETE" });
},
list: (prefix) => {
return fetch(`${REPLIT_DB_URL}?prefix=${encodeURIComponent(prefix)}`);
},
};
}
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);
}
1
2
3
4
5
6
7
8
let { inbox } = await import("https://esm.town/v/claytn/inbox");
export const tell = (msg) => {
if (!inbox) {
inbox = [];
}
inbox.push({ msg, sent: Date.now() });
};
Next