aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2021-03-22 13:24:16 -0500
committerRossTheRoss <mstrapp@protonmail.com>2021-03-22 13:24:16 -0500
commit4b63b00c32b767d24b114d38dab8c154d6321a7b (patch)
tree306922a0663513ff37241716d24084b6f1a985f7 /csci4131
parentalmost delete file (diff)
downloadhomework-4b63b00c32b767d24b114d38dab8c154d6321a7b.tar
homework-4b63b00c32b767d24b114d38dab8c154d6321a7b.tar.gz
homework-4b63b00c32b767d24b114d38dab8c154d6321a7b.tar.bz2
homework-4b63b00c32b767d24b114d38dab8c154d6321a7b.tar.lz
homework-4b63b00c32b767d24b114d38dab8c154d6321a7b.tar.xz
homework-4b63b00c32b767d24b114d38dab8c154d6321a7b.tar.zst
homework-4b63b00c32b767d24b114d38dab8c154d6321a7b.zip
Start Extra credit
Diffstat (limited to 'csci4131')
-rwxr-xr-xcsci4131/hw5/strap012_hw5/client/contacts.html23
-rwxr-xr-xcsci4131/hw5/strap012_hw5/client/stock.html36
-rwxr-xr-xcsci4131/hw5/strap012_hw5/createServer.js9
3 files changed, 44 insertions, 24 deletions
diff --git a/csci4131/hw5/strap012_hw5/client/contacts.html b/csci4131/hw5/strap012_hw5/client/contacts.html
index 2e4bf65..15e4032 100755
--- a/csci4131/hw5/strap012_hw5/client/contacts.html
+++ b/csci4131/hw5/strap012_hw5/client/contacts.html
@@ -23,19 +23,16 @@
var contacts = a.contacts;
for (let i = 0; i < contacts.length; i++) {
var contact = contacts[i];
- var row = table.insertRow(-1);
- var nam = row.insertCell(0);
- nam.innerHTML = contact.name;
- var cat = row.insertCell(1);
- cat.innerHTML = contact.category;
- var loc = row.insertCell(2);
- loc.innerHTML = contact.location;
- var con = row.insertCell(3);
- con.innerHTML = contact.contact;
- var ema = row.insertCell(4);
- ema.innerHTML = contact.email;
- var url = row.insertCell(5);
- url.innerHTML = "<a href =" + contact.website_url + ">" + contact.website_url + "</a>";
+ var row = table.insertRow();
+ for (var j in contact) {
+ if (j != "website_url") {
+ var value = row.insertCell();
+ value.innerHTML = contact[j];
+ } else {
+ var url = row.insertCell();
+ url.innerHTML = "<a href =" + contact[j] + ">" + contact[j] + "</a>";
+ }
+ }
}
}
diff --git a/csci4131/hw5/strap012_hw5/client/stock.html b/csci4131/hw5/strap012_hw5/client/stock.html
index 91f8493..b55ffcb 100755
--- a/csci4131/hw5/strap012_hw5/client/stock.html
+++ b/csci4131/hw5/strap012_hw5/client/stock.html
@@ -7,6 +7,9 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style>
+ pre {
+ max-height: 12em;
+ }
textarea {
width: 100%;
min-height: 30rem;
@@ -47,7 +50,7 @@
<td class="col-md-6">Company</td>
<td class="col-md-6">
<div class="form-group">
- <select name="Company">
+ <select id="Company" name="Company">
<option value="GME">Gamestop</option>
<option value="MSFT">Microsoft</option>
<option value="BA">Boeing Company</option>
@@ -60,7 +63,7 @@
</tr>
<tr>
<td colspan="2">
- <button type="button">Get Data</button>
+ <button type="button" onclick="Click()">Get Data</button>
</td>
</tr>
</tbody>
@@ -77,15 +80,36 @@
<table class="table" id="StockData">
<thead>
<tr>
- <th scope="col">Company-MetaData</th>
- <th scope="col">Stock-Info</th>
+ <th scope="col" id="meta">Company-MetaData</th>
+ <th scope="col" id="Time">Stock-Info</th>
</tr>
</thead>
+ <pre>
<tbody></tbody>
+ </pre>
</table>
</div>
- <!-- <script>
+ <script>
+ function Click() {
+ var comp = document.getElementById("Company").value;
+ var xmlhttp = new XMLHttpRequest();
+ var url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + comp + "&apikey=8MWSNPDWKH0BTBH2";
+ xmlhttp.onreadystatechange = function () {
+ if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
+ var parse = JSON.parse(xmlhttp.responseText);
+ var table = document.getElementById("StockData").getElementsByTagName("tbody")[0];
+ var row = table.insertRow();
+ for (var i in parse) {
+ var cell = row.insertCell();
+ cell.innerHTML = "<pre>" + JSON.stringify(parse[i], undefined, 2) + "</pre>";
+ }
+ }
+ }
+ xmlhttp.open("GET", url, true);
+ xmlhttp.send();
+
+ }
/* TODO:
/ Bonus 1. Request the TIME_SERIES_DAILY endpoint of alphavantage API
/ for the company selected in the dropdown. Display the JSON
@@ -94,6 +118,6 @@
/ line chart using Chart.js to the chartContainer div. Ensure
/ the chart meets all requirements from the HW writeup.
/*/
- </script> -->
+ </script>
</body>
</html>
diff --git a/csci4131/hw5/strap012_hw5/createServer.js b/csci4131/hw5/strap012_hw5/createServer.js
index bd25de5..9c108cd 100755
--- a/csci4131/hw5/strap012_hw5/createServer.js
+++ b/csci4131/hw5/strap012_hw5/createServer.js
@@ -78,14 +78,13 @@ function POST(req, res) {
jsonO["email"] = postObj.email;
jsonO["website_name"] = postObj.website_name;
jsonO["website_url"] = postObj.website_url;
- let read = fs.readFile('./contacts.json', 'utf8', function(err, data) {
+ fs.readFile('./contacts.json', 'utf8', function(err, data) {
var file = JSON.parse(data);
file.contacts.push(jsonO);
var string = JSON.stringify(file);
fs.writeFile('./contacts.json', string, function(err, data) {
console.log(string);
- });
- });
-
- });
+ }); //Write clojure
+ }); //Read clojure
+ }); //req clojure
} \ No newline at end of file