PS:336 – Relaxing by Coding.

So one of my side little projects of late has been the coding of tools to better keep me up-to-date on my coins – my previous post (334) I mentioned the small coding project and I think I may write a small page for it and update the code as I have updates, currently on version .04:

<?php

/****
Coins.php (v.04)

A simple API call to get the value of a coin in the user's desired currency, great for using in Google Sheets (Use: =IMPORTDATA("yoururl") or if you simply want to grab
the current value of a certain coin. Currently geared towards USD, but hope in next version to add proper currency markings for the amount conversion.


## Changelog

.01 -   First Release
.02 -   Adjustments to code & calling methods.
        Changed from XML output to plaintext for use of IMPORTDATA vs IMPORTXML
.03 -   Removed dual posting of plaintext price for import & added amount conversion.
        Commented code.
.04 -   Added Conversion for ATM without Value Text for Onion pull - Also adding $ for easier formatting on Onion curl call.
***/


//Get Data
$url = file_get_contents("https://min-api.cryptocompare.com/data/price?fsym=".$_REQUEST['coin']."&tsyms=".$_REQUEST['curr']."");
$json = json_decode($url,true);
//Check for Amount to Convert
if ($_REQUEST['atm'] != '') {
$value = $_REQUEST['atm'] * $json[$_REQUEST['curr']];
$tvalue = round($value,2);
echo "$".$tvalue;
} else {
//no amount? provide plaintext response for dollar amount.
print $json[$_REQUEST['curr']];
}
?>

Well, it’s quite handy, feel free to use it if you need to, but basically, it’s allowed me to use my Ometa2+’s OLED screen to every 5 minutes update the current value of coins! Here’s a peek:

Enjoying it a lot, really neat to look over and not have to re-open my Google Docs, just a glance and the screen presents all the goodies.

Maybe I’ll write it all up and send it over to the Onion forums, it is simple, purely informational, but thinking about maybe converting a bitcoin icon -> LCD file and place it on the right side? Long-term if the value is huge (they say it will be) then it will overlap, but for now, a bash script, php script, and a cron job give me some info at a glance.

%d bloggers like this: