-
Notifications
You must be signed in to change notification settings - Fork 52
Feature: currency rates #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
yammesicka
merged 31 commits into
PythonFreeCourse:develop
from
advaa123:feature/currency-js
Feb 7, 2021
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
9919f2e
help
advaa123 c6cb120
merging
advaa123 7349c9e
merging
advaa123 324a5f3
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
advaa123 e2c5b06
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
advaa123 8127128
updated develop
advaa123 f2bc4e9
currency
advaa123 85fceab
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
advaa123 5f11aeb
Currency feature
advaa123 323b16c
Merge branch 'develop' of https://github.com/PythonFreeCourse/calenda…
advaa123 e3267e0
Merge develop into feature/currency-js
advaa123 26e4df2
Merge develop into feature/currency-js
advaa123 e437c17
Merge develop into feature/currency-js
advaa123 0dd6c75
Merge develop into feature/currency-js
advaa123 c20ebdd
Currency rates daily feature
advaa123 057981e
Flake8 fixes
advaa123 23624b8
Flake8 fixes
advaa123 b6c6831
Flake8 fixes
advaa123 27af394
flake8 fixes
advaa123 4a39595
final fixes
advaa123 d5dc607
Split fixtures and tests to different files
advaa123 a746b1e
Split fixtures and tests to different files
advaa123 89e03ff
Fixes for Yam
advaa123 3e2ed01
Merge branch 'develop' into feature/currency-js
advaa123 2faf089
Fixes for Yam
advaa123 b6c30cf
Merge branch 'feature/currency-js' of https://github.com/advaa123/cal…
advaa123 e3e792b
Fixes for Yam
advaa123 c44d786
Merge branch 'develop' into feature/currency-js
advaa123 dc3e7ea
Collapse fix
advaa123 c873746
Merge branch 'feature/currency-js' of http://github.com/advaa123/cale…
advaa123 6885f88
Collapse fix
advaa123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import datetime | ||
|
||
from app.dependencies import templates | ||
from fastapi import APIRouter, Request | ||
|
||
|
||
router = APIRouter() | ||
|
||
# TODO: Add this as a feature to the calendar view/ | ||
# day view/features panel frontend | ||
|
||
|
||
@router.get("/currency") | ||
def today_currency(request: Request): | ||
"""Current day currency router""" | ||
|
||
date = datetime.date.today().strftime("%Y-%m-%d") | ||
return currency(request, date) | ||
|
||
|
||
@router.get("/currency/{date}") | ||
def currency(request: Request, date: str): | ||
"""Custom date currency router""" | ||
|
||
# TODO: get user default/preferred currency | ||
base = "USD" | ||
|
||
return templates.TemplateResponse("currency.html", { | ||
"request": request, | ||
"base": base, | ||
"date": date | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
div[data-visible='0'] { | ||
display: none; | ||
} | ||
div[data-visible='1'] { | ||
display: block; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
function getCurrency(baseCurrency, dateToday) { | ||
const showCurrencyElement = document.getElementById("showCurrency") | ||
const currencyViewElement = document.getElementById("currencyView"); | ||
const myUrl = 'https://api.exchangeratesapi.io/' + dateToday + '?base=' + baseCurrency | ||
|
||
async function getResponse(myUrl) { | ||
let response = await fetch(myUrl); | ||
if (response.ok) { | ||
let result = await response.json(); | ||
currencyViewElement.innerHTML = ""; | ||
showCurrencyElement.dataset.visible = "1"; | ||
return result; | ||
} | ||
} | ||
|
||
getResponse(myUrl) | ||
.then(result => buildCurrencyList(result)); | ||
|
||
function buildCurrencyList(data) { | ||
function getListItem() { | ||
const listItem = document.createElement("li"); | ||
listItem.className = "list-group-item title_size_small"; | ||
return listItem; | ||
} | ||
|
||
function createBoldListItem(fieldString, currViewElem) { | ||
const listItem = getListItem(); | ||
const boldItem = document.createElement("strong"); | ||
boldItem.innerHTML = fieldString; | ||
listItem.appendChild(boldItem); | ||
currViewElem.appendChild(listItem); | ||
} | ||
|
||
function getAnchorItem() { | ||
const linkItem = document.createElement("a"); | ||
linkItem.setAttribute("href", "javascript:void(0)"); | ||
linkItem.setAttribute("id", key); | ||
linkItem.innerText = key; | ||
return linkItem; | ||
} | ||
|
||
function getRatesItem(fieldString) { | ||
let ratesItem = document.createElement("div"); | ||
ratesItem.setAttribute("style", "display: inline;") | ||
ratesItem.innerHTML = fieldString; | ||
return ratesItem; | ||
} | ||
|
||
function createAllElements(dataRates, baseCurr, currViewElem) { | ||
for (key in dataRates) { | ||
if (key !== baseCurr) { | ||
let listItem = getListItem(); | ||
let linkItem = getAnchorItem(); | ||
let ratesItem = getRatesItem(": " + dataRates[key]); | ||
listItem.appendChild(linkItem); | ||
listItem.appendChild(ratesItem); | ||
currViewElem.appendChild(listItem); | ||
} | ||
} | ||
} | ||
|
||
// Create Base currency list item | ||
createBoldListItem("BASE: " + baseCurrency, currencyViewElement); | ||
// Create all rates list items | ||
createAllElements(data.rates, baseCurrency, currencyViewElement); | ||
// Create date list item | ||
createBoldListItem(dateToday, currencyViewElement); | ||
|
||
return true; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" | ||
integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="{{ url_for('static', path='/currency.css') }}"> | ||
<title>currency</title> | ||
</head> | ||
|
||
<body> | ||
<div id="showCurrency" data-visible="0"> | ||
<p style="margin: 1rem;"> | ||
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample" | ||
aria-expanded="false" aria-controls="collapseExample"> | ||
Currency</button> | ||
<div class="row" style="margin: 1rem; width: 14rem;"> | ||
<div class="col"> | ||
<div class="collapse multi-collapse" id="collapseExample"> | ||
<ul class="list-group list-group-flush" id="currencyView"> | ||
<!-- JS currency content --> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script type="text/javascript" src="{{ url_for('static', path='/currency.js')}}"></script> | ||
<script type="text/javascript"> | ||
getCurrency("{{ base | safe }}", "{{ date | safe }}"); | ||
document.getElementById("currencyView").addEventListener("click", function (e) { | ||
if (e.target && e.target.nodeName == "A") { | ||
getCurrency(e.target.id, "{{ date | safe }}"); | ||
} | ||
}, false); | ||
</script> | ||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" | ||
crossorigin="anonymous"></script> | ||
</body> | ||
|
||
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CURRENCY = '/currency' | ||
CUSTOM_DATE = "/2021-1-3" | ||
|
||
|
||
def test_router_good(client): | ||
resp = client.get(CURRENCY) | ||
assert resp.ok | ||
resp = client.get(CURRENCY + CUSTOM_DATE) | ||
assert resp.ok | ||
assert b'Currency</button>' in resp.content |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.