aboutsummaryrefslogtreecommitdiff
path: root/frontend/src/SECAPIData.js
diff options
context:
space:
mode:
authorMichael Foiani <sotech117@michaels-mbp-3.lan>2021-04-10 01:06:49 -0400
committerMichael Foiani <sotech117@michaels-mbp-3.lan>2021-04-10 01:06:49 -0400
commit6384bebb363ab75e9f1d567ed179e08057828171 (patch)
treee32ae3210b8bc9ff10db0283089e8ab79bc0fd48 /frontend/src/SECAPIData.js
parent6ecdd804ddb8d2ce2166b71cf0e8929a5a68215e (diff)
Finally have an xml parser that reads the urls and inserts data into database consistently. A couple functionality todos, then need to do some more edge testing.
Diffstat (limited to 'frontend/src/SECAPIData.js')
-rw-r--r--frontend/src/SECAPIData.js38
1 files changed, 26 insertions, 12 deletions
diff --git a/frontend/src/SECAPIData.js b/frontend/src/SECAPIData.js
index 3e670d3..b1b4939 100644
--- a/frontend/src/SECAPIData.js
+++ b/frontend/src/SECAPIData.js
@@ -1,15 +1,21 @@
-import React, {useState, useRef} from 'react';
+import React, {useState, useEffect} from 'react';
import Button from './Button';
function SECAPIData() {
-
const [dataToBackend, setDataToBackend] = useState([]);
const [displayData, setDisplayData] = useState("");
const requestData = () => {
+ // End early in debug to avoid too many requests.
+ if (dataToBackend.length !== 0) {
+ sendToBackend();
+ return;
+ }
+
+ console.log("Makig request...");
let date = new Date()
let today = date.toISOString().slice(0, 10);
@@ -33,25 +39,30 @@ function SECAPIData() {
})
.then(res => res.json())
.then(data => {
- let list = new Array();
- data.filings.forEach(function(filing) {
- if (filing.ticker == "") {
- list.push(filing.filedAt);
- list.push(filing.documentFormatFiles[1].documentUrl);
+ let list = [];
+ data.filings.forEach(filing => {
+ if (filing.ticker === "") {
+ // TODO: why are there repitions of urls.
+ list.push({
+ timestamp: filing.filedAt,
+ url: filing.documentFormatFiles[1].documentUrl
+ });
}
})
setDataToBackend(list);
- console.log(list);
})
- .catch(function (error) {
+ .catch(error => {
console.log(error);
});
+ }
+
+ const sendToBackend = () => {
+ console.log(dataToBackend);
-
fetch("http://localhost:4567/data", {
method: "POST",
body: JSON.stringify({
- "data" : {dataToBackend}
+ "data" : dataToBackend
}),
headers: {
"Content-Type": "application/json",
@@ -66,7 +77,10 @@ function SECAPIData() {
.catch(function (error) {
console.log(error);
});
- }
+ }
+
+ // This hook is autocalled once the setDataToBackend takes effect.
+ useEffect(() => sendToBackend(), [dataToBackend]);
return (
<div>