Public
Script
November 29, 2023
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
let currentDate = new Date();
let endDate = Math.floor(currentDate.getTime() / 1000);
let startDate = Math.floor(currentDate.setDate(currentDate.getDate() - 7) / 1000);
export async function fetchPinataPosts() {
try {
const soRes = await fetch(
`https://api.stackexchange.com/2.3/questions?fromdate=${startDate}&todate=${endDate}&order=desc&sort=creation&tagged=pinata&site=stackoverflow`,
{
method: "GET",
},
);
const soResData = await soRes.json();
const soItemsArray = soResData.items;
const newSOItems = soItemsArray
.filter(item => !item.is_answered)
.map(item => {
return {
title: item.title,
link: item.link,
date: new Date(item.creation_date * 1000).toLocaleString(),
};
});
const seRes = await fetch(
`https://api.stackexchange.com/2.3/questions?fromdate=${startDate}&todate=${endDate}&order=desc&sort=creation&tagged=pinata&site=ethereum`,
{
method: "GET",
},
);
const seResData = await seRes.json();
const seItemsArray = seResData.items;
const newSEItems = seItemsArray
.filter(item => !item.is_answered)
.map(item => {
return {
title: item.title,
link: item.link,
date: new Date(item.creation_date * 1000).toLocaleString(),
};
});
let formattedArray1 = newSEItems.map(obj => {
return `Post: <a href='${obj.link}'>${obj.title}</a></br>
Creation Date: ${obj.date} </br> </br>`;
}).join("");
let formattedArray2 = newSOItems.map(obj => {
return `Post: <a href='${obj.link}'>${obj.title}</a></br>
Creation Date: ${obj.date} </br> </br>`;
}).join("");
let emailText = `
<h2>Posts about Pinata on Ethereum:</h2></br>
${formattedArray1}
<h2>Posts about Pinata on Stack Overflow:</h2></br>
${formattedArray2}
`;
return emailText;
} catch (error) {
console.error("Error fetching data:", error);
return null;
}
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
November 29, 2023