finished product
This commit is contained in:
0
main/__init__.py
Normal file
0
main/__init__.py
Normal file
BIN
main/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
main/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
BIN
main/__pycache__/admin.cpython-36.pyc
Normal file
BIN
main/__pycache__/admin.cpython-36.pyc
Normal file
Binary file not shown.
BIN
main/__pycache__/apps.cpython-36.pyc
Normal file
BIN
main/__pycache__/apps.cpython-36.pyc
Normal file
Binary file not shown.
BIN
main/__pycache__/models.cpython-36.pyc
Normal file
BIN
main/__pycache__/models.cpython-36.pyc
Normal file
Binary file not shown.
BIN
main/__pycache__/urls.cpython-36.pyc
Normal file
BIN
main/__pycache__/urls.cpython-36.pyc
Normal file
Binary file not shown.
BIN
main/__pycache__/views.cpython-36.pyc
Normal file
BIN
main/__pycache__/views.cpython-36.pyc
Normal file
Binary file not shown.
3
main/admin.py
Normal file
3
main/admin.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
main/apps.py
Normal file
5
main/apps.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class MainConfig(AppConfig):
|
||||
name = 'main'
|
||||
0
main/migrations/__init__.py
Normal file
0
main/migrations/__init__.py
Normal file
BIN
main/migrations/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
main/migrations/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
3
main/models.py
Normal file
3
main/models.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
79
main/static/main/styles.css
Normal file
79
main/static/main/styles.css
Normal file
@@ -0,0 +1,79 @@
|
||||
#fib {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.fib {
|
||||
background-color: rgba(0,0,255,0.1);
|
||||
}
|
||||
|
||||
.fib-left {
|
||||
float: left;
|
||||
display: inline-block;
|
||||
margin-right: 4px;
|
||||
}
|
||||
|
||||
.fib-right {
|
||||
float: right;
|
||||
display: inline-block;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.shadowed {
|
||||
text-shadow: 1px 1px 2px black;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.nice-box {
|
||||
font-family: 'helvetica neue', helvetica, sans-serif;
|
||||
padding: 3px 10px;
|
||||
margin: 10px;
|
||||
border-radius: 10px;
|
||||
border-width: 2px;
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
.flex-rows {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
#quandl {
|
||||
margin: 10px;
|
||||
}
|
||||
|
||||
.stuff-box {
|
||||
font-family: 'helvetica neue', helvetica, sans-serif;
|
||||
letter-spacing: 1px;
|
||||
text-transform: capitalize;
|
||||
text-align: center;
|
||||
padding: 3px 10px;
|
||||
margin: 10px;
|
||||
cursor: pointer;
|
||||
border-radius: 10px;
|
||||
border-width: 2px;
|
||||
border-style: solid;
|
||||
}
|
||||
|
||||
.red {
|
||||
border-color: rgb(255,0,0);
|
||||
background: rgb(180,60,60);
|
||||
box-shadow: 1px 1px 2px rgba(200,0,0,0.4);
|
||||
}
|
||||
|
||||
.yellow {
|
||||
border-color: rgb(255,255,0);
|
||||
background: rgb(180,180,60);
|
||||
box-shadow: 1px 1px 2px rgba(200,200,0,0.4);
|
||||
}
|
||||
|
||||
.blue {
|
||||
border-color: rgb(0,0,255);
|
||||
background: rgb(60,60,180);
|
||||
box-shadow: 1px 1px 2px rgba(0,0,200,0.4);
|
||||
}
|
||||
|
||||
.green {
|
||||
border-color: rgb(0,255,0);
|
||||
background: rgb(60,180,60);
|
||||
box-shadow: 1px 1px 2px rgba(0,200,0,0.4);
|
||||
}
|
||||
97
main/templates/main/index.html
Normal file
97
main/templates/main/index.html
Normal file
@@ -0,0 +1,97 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<html>
|
||||
<head>
|
||||
{% load static %}
|
||||
<title>Fetching data from Quandl</title>
|
||||
<link rel="stylesheet" type="text/css" href= "{% static "/main/styles.css" %}"/>
|
||||
</head>
|
||||
<body onload="fetch()">
|
||||
<div class="shadowed green nice-box">
|
||||
<h2>Worth Your Weight In Gold</h2>
|
||||
</div>
|
||||
|
||||
<form>
|
||||
<input type = "number" step = "%.01" id = "userWeight"/>
|
||||
<div class="shadowed blue nice-box flex-rows">
|
||||
<button type="button" onclick="getConversion()">Calculate!</button>
|
||||
</div>
|
||||
<div class= "shadowed red stuff-box flex-rows">
|
||||
<p id="quandl"></p>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
var apiKey = 'yNXwKyYV35g-Uc-BnFxg';
|
||||
var value;
|
||||
|
||||
function getStartDate() {
|
||||
var d = new Date(Date.now()),
|
||||
month = '' + (d.getMonth() + 1),
|
||||
day = '' + d.getDate()-5,
|
||||
year = d.getFullYear();
|
||||
if (month.length < 2) month = '0' + month;
|
||||
if (day.length < 2) day = '0' + day;
|
||||
return [year, month, day].join('-');
|
||||
}
|
||||
function getEndDate() {
|
||||
var d = new Date(Date.now()),
|
||||
month = '' + (d.getMonth() + 1),
|
||||
day = '' + d.getDate(),
|
||||
year = d.getFullYear();
|
||||
if (month.length < 2) month = '0' + month;
|
||||
if (day.length < 2) day = '0' + day;
|
||||
return [year, month, day].join('-');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var start = getStartDate(),
|
||||
end = getEndDate();
|
||||
|
||||
var goldRUrl = "https://www.quandl.com/api/v3/datasets/LBMA/GOLD.json?api_key=" + apiKey +
|
||||
"&column_index=2&start_date=" + start + "&end_date=" + end;
|
||||
|
||||
var myData;
|
||||
var theData;
|
||||
var getConversion = function() {
|
||||
var weightLbs = +document.getElementById("userWeight").value;
|
||||
var unitconvURL = "http://127.0.0.1:8000/conversion/json?from=lbs&to=t_oz&value=" + weightLbs;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', unitconvURL);
|
||||
xhr.responseType = 'json';
|
||||
xhr.onload = function() {
|
||||
myData = xhr.response;
|
||||
console.log(myData);
|
||||
if ('error' in myData){document.querySelector('#quandl').textContent = "Error: "+ myData['error']}
|
||||
else {
|
||||
var weightValue = myData['value'] * theData.dataset.data[0][1];
|
||||
var weightValue = parseFloat(weightValue).toFixed(2);
|
||||
document.querySelector('#quandl').textContent = "Your weight in gold: $"+weightValue;
|
||||
}
|
||||
};
|
||||
xhr.send();
|
||||
};
|
||||
|
||||
|
||||
var fetch = function() {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', goldRUrl);
|
||||
xhr.responseType = 'json';
|
||||
xhr.onload = function() {
|
||||
theData = xhr.response;
|
||||
console.log(theData);
|
||||
value = theData.dataset.data[0][1];
|
||||
{# if (theData.dataset.data){document.querySelector('#quandl').textContent = theData.dataset.data[0][1] + " Some data was fetched into 'theData'" + end;}#}
|
||||
// document.title = theData.dataset.name + " from Quandl's API"};
|
||||
};
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
3
main/tests.py
Normal file
3
main/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
7
main/urls.py
Normal file
7
main/urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
]
|
||||
14
main/views.py
Normal file
14
main/views.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from django.shortcuts import render
|
||||
from django.http import HttpResponse
|
||||
from django.template import loader
|
||||
from django.utils import timezone
|
||||
from django.urls import reverse
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
# Create your views here.
|
||||
def index(request):
|
||||
template = loader.get_template('main/index.html')
|
||||
context = {
|
||||
|
||||
}
|
||||
return HttpResponse(template.render(context, request))
|
||||
Reference in New Issue
Block a user