Jump to content
Sign in to follow this  
buzzkillb

InkyPhat Display Explorer API [D] [Raspbian]

Recommended Posts

IMG_20190310_150204.thumb.jpg.1b869bc7c670d4b5247244a540c28bca.jpg

First install InkyPhat on Raspbian on your pi. Pi Zero W might look amazing doing this if you are only pulling info from other places. For now I am only pulling the data from coinexplorer to show a proof of concept. I got the yellow one, but forgot to get the GPIO header for my pi zero w, so its stuck on the Pi3 for now.

IMPORTANT: I had to use this line on the pi zero w and reboot after installing the software.

curl https://get.pimoroni.com/i2c  | sudo bash

I got mine from amazon here -> https://amzn.to/2NTI8FA
https://shop.pimoroni.com/products/inky-phat?variant=12549254905939

https://github.com/buzzkillb/InkyPhat

curl https://get.pimoroni.com/inky | bash

As a test run use this code to show the Denarius Burn Address Balance.

denariusbalance.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, json

from inky import InkyPHAT

inky_display = InkyPHAT("yellow")
inky_display.set_border(inky_display.WHITE)

from PIL import Image, ImageFont, ImageDraw

print("""Inky pHAT: Denarius displays blockchain information.
""")

img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)

from font_fredoka_one import FredokaOne

font = ImageFont.truetype(FredokaOne, 22)

daddress = "DNRXXXXXXXXXXXXXXXXXXXXXXXXXZeeDTw"
url = "https://www.coinexplorer.net/api/v1/D/address/balance?address=%s" % daddress
response = urllib.urlopen(url)
data = json.loads(response.read())
dbalance = ("D balance=" + data['result'][daddress])

w, h = font.getsize(dbalance)
x = (inky_display.WIDTH / 2) - (w / 2)
y = (inky_display.HEIGHT / 2) - (h / 2)

draw.text((x, y), dbalance, inky_display.YELLOW, font)
inky_display.set_image(img)
inky_display.show()

w, h = font.getsize(daddress)
x = (inky_display.WIDTH / 2) - (w / 2)
y = (inky_display.HEIGHT / 2) - (h / 2)

draw.text((x, y), daddress, inky_display.YELLOW, font)
inky_display.set_image(img)
inky_display.show()

To run type

python2 denariusbalance.py

Cronjob every 15 minutes

crontab -e

*/15 * * * * (cd /home/user/whereever/this/is/located; python2 denariusbalance.py)

This is the version I am playing around with to display more than a one liner balance.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, json

from inky import InkyPHAT

inky_display = InkyPHAT("yellow")
inky_display.set_border(inky_display.WHITE)

from PIL import Image, ImageFont, ImageDraw

print("""Inky pHAT: Denarius displays blockchain information.
""")

img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)

from font_fredoka_one import FredokaOne

font16 = ImageFont.truetype(FredokaOne, 16)
font8 = ImageFont.truetype(FredokaOne, 8)

daddress = "DNRXXXXXXXXXXXXXXXXXXXXXXXXXZeeDTw"
url = "https://www.coinexplorer.net/api/v1/D/address/balance?address=%s" % daddress
response = urllib.urlopen(url)
data = json.loads(response.read())
dbalance = ("D balance=" + data['result'][daddress])

w, h = font16.getsize(dbalance)
w1, h1 = font8.getsize(daddress)
x = (inky_display.WIDTH / 2) - (w / 2)
y = (inky_display.HEIGHT / 4) - (h / 4)
x1 = (inky_display.WIDTH / 2) - (w1 / 2)
y1 = (inky_display.HEIGHT / 2) - (h1 / 2)

draw.text((x, y), dbalance, inky_display.YELLOW, font16)
draw.text((x1, y1), daddress, inky_display.YELLOW, font8)
inky_display.set_image(img)
inky_display.show()

 

  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

Line by line breakdown of this so you can abuse any explorer for your favorite cryptocurrency. I just learned basic python about an hour ago, so anyone wants to throw info in here, please do.

Sets the address using daddress as the variable.

daddress = "DNRXXXXXXXXXXXXXXXXXXXXXXXXXZeeDTw"

Sets the URL. %s heads on over to stick that daddress variable from above into the complete block explorer API address.

url = "https://www.coinexplorer.net/api/v1/D/address/balance?address=%s" % daddress

This does something.

response = urllib.urlopen(url)

This loads the JSON from that URL variable of the complete address.

data = json.loads(response.read())

Stores the text D balance= and puts the data from the JSON next to the = sign.

dbalance = ("D balance=" + data['result'][daddress])

This would print the line to the command line. But we want InkyPhat to do its thing so we get the rest of the gobbly gook from the code above.

print dbalance

 

  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

The idea is that if the e-ink takes 20 seconds to refresh, why not pull different stats in every 15 minutes or so running cronjobs. This example I show pulling in JSON data, rounding to get 3 decimal place precision, then multiplying the POW/POS decimals by 100 to get a percentage (probably did this backwards). I am converting floats and strings like this because I have no clue how to one liner and compact each variable. Then I print all one line with line break '\n' between variable and this time I am not centering the text and instead starting from point 5,20, all at a nice font size of 20.

Data wise I am thinking this goes on a pi zero w still, so no running the daemon to pull stats from yet.

If you end up using denarius.win, donate Denarius please to the site owner. @KawaiiCrypto

IMG_20190310_162331.thumb.jpg.480fea6e6ffa578a569e8e1fe3bfd0a3.jpg

denariusstats.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, json

from inky import InkyPHAT

inky_display = InkyPHAT("yellow")
inky_display.set_border(inky_display.WHITE)

from PIL import Image, ImageFont, ImageDraw

print("""Inky pHAT: Denarius displays blockchain information.
""")

img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)

from font_fredoka_one import FredokaOne

font = ImageFont.truetype(FredokaOne, 20)

url = "http://denarius.win/stats.json"
response = urllib.urlopen(url)
data = json.loads(response.read())
winpow2 = round(data['pow'],3)
winpowresult = float(winpow2) * 100
winpos2 = round(data['pos'],3)
winposresult = float(winpos2) * 100
winblocktime2 = round(data['blocktime'],2)
winpow = ("POW: " + str(winpowresult) + "%")
winpos = ("POS: " + str(winposresult) + "%")
winblocktime = ("Blocktime: " + str(winblocktime2) + " sec")
winstats = (winpow + '\n' + winpos + '\n' + winblocktime)

draw.text((5, 20), winstats, inky_display.YELLOW, font)
inky_display.set_image(img)
inky_display.show()

 


Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

Kind of silly how it works to add an image, but basically follow their own guide how to create this in GIMP. Also be aware the canvas size has to be 212x104 pixels. Make it woooork.

https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-inky-phat

IMG_20190310_170359.thumb.jpg.2183655f3fd9967e3489b65ee40bfcac.jpg

from inky import InkyPHAT

inky_display = InkyPHAT("yellow")
inky_display.set_border(inky_display.WHITE)

from PIL import Image, ImageFont, ImageDraw
img = Image.open("/home/pi/inkyD.png")
inky_display.set_image(img)
inky_display.show()

Sample GIMP png for testing.

inkyD.png.2a8d1136ba8d39ebe93866a6cbeb0643.png

  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

Some sample cronjobs and resulting files that can be thrown into this. Any coin daemon can be done in a similar way. Below takes the output and throws into a file every 60 seconds. Then pull want you want from a cronjob and your InkyPhat python file. Example: post fortunastake count every hour, while the fscount.txt file is constantly updating every minute.

gentle hint, you need to run the denariusd daemon for below to work 😘

* * * * * /usr/local/bin/denariusd fortunastake count > /home/pi/fscount.txt
* * * * * /usr/local/bin/denariusd getblockcount > /home/pi/height.txt
* * * * * /usr/local/bin/denariusd getinfo > /home/pi/getinfo.json
* * * * * /usr/local/bin/denariusd getmininginfo > /home/pi/getmininginfo.json
* * * * * /usr/local/bin/denariusd getpeerinfo > /home/pi/getpeerinfo.json

  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

Now you want to throw Bitcoin Price into your new Cryptocurrency scroller? Pulling API info from coindesk.

IMG_20190310_181908.thumb.jpg.fda241b0152cb0d64c8396064243323e.jpg

btcprice.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, json

from inky import InkyPHAT

inky_display = InkyPHAT("yellow")
inky_display.set_border(inky_display.YELLOW)

from PIL import Image, ImageFont, ImageDraw

print("""Inky pHAT: Bitcoin Price information.
""")

img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)

from font_fredoka_one import FredokaOne

font = ImageFont.truetype(FredokaOne, 24)

url = "https://api.coindesk.com/v1/bpi/currentprice.json"
response = urllib.urlopen(url)
data = json.loads(response.read())
chartname = data['chartName']
btcusd = data['bpi']['USD']['rate_float']
btceur = data['bpi']['EUR']['rate_float']
bitcoinprice = (chartname + '\n' + "$ " + str(btcusd) + '\n' + "E " + str(btceur))

# Load our backdrop image
img = Image.open("/home/pi/btc_yellow.png")
draw = ImageDraw.Draw(img)

draw.text((10, 10), bitcoinprice, inky_display.YELLOW, font)
inky_display.set_image(img)
inky_display.show()

Sample yellow bitcoin logo I am using.

btc_yellow.png.3a5230b515e467b6a91c63476055f7eb.png

  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

One last one pulling stats from coinpaprika API. The idea is I have changed a thing or two each go around.

This pulls the high, low, volume, and for some reason missing marketcap in $USD terms with one of the D logos from the visual guide, https://github.com/carsenk/denarius/wiki/Denarius-Visual-Guide

IMG_20190310_190540.thumb.jpg.1a2ab634b3bc35ef548f04e2ff72fd68.jpg

dprice.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, json

from inky import InkyPHAT

inky_display = InkyPHAT("yellow")
inky_display.set_border(inky_display.YELLOW)

from PIL import Image, ImageFont, ImageDraw

print("""Inky pHAT: Denarius Price information.
""")

img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)

from font_fredoka_one import FredokaOne

font = ImageFont.truetype(FredokaOne, 22)

url = "https://api.coinpaprika.com/v1/coins/d-denarius/ohlcv/latest"
response = urllib.urlopen(url)
data = json.loads(response.read())
dhigh = data[0]['high']
dlow = data[0]['low']
dvol = data[0]['volume']
dmc = data[0]['market_cap']
denariusprice = ("$ " + str(dhigh) + '\n' + "$ " + str(dlow) + '\n' + "$ " + str(dvol) + '\n' + "$ " + '\n' + str(dmc))

# Load our backdrop image
img = Image.open("/home/pi/d-logo.png")
draw = ImageDraw.Draw(img)

#img = Image.open("/home/pi/btc_yellow.png")
draw.text((10, 0), denariusprice, inky_display.BLACK, font)
inky_display.set_image(img)
inky_display.show()

included png for Denarius logo

d-logo.png.f44638925f2c070183a6d57e049200b5.png

  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

Personal Favorite combining all the above into showing the Denarius Logo+Text with Balance and Address below. Since the D is too big, the address cuts off, but no big deal.

IMG_20190310_201405.thumb.jpg.04cef6d1256db232df14e894175d1027.jpg

dbalance.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, json

from inky import InkyPHAT

inky_display = InkyPHAT("yellow")
inky_display.set_border(inky_display.YELLOW)

from PIL import Image, ImageFont, ImageDraw

print("""Inky pHAT: Denarius displays blockchain information.
""")

img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)

from font_fredoka_one import FredokaOne

font = ImageFont.truetype(FredokaOne, 16)

daddress = "DNRXXXXXXXXXXXXXXXXXXXXXXXXXZeeDTw"
url = "https://www.coinexplorer.net/api/v1/D/address/balance?address=%s" % daddress
response = urllib.urlopen(url)
data = json.loads(response.read())
dbalance = ("D Balance=" + data['result'][daddress] + '\n' + daddress)

# Load our backdrop image
img = Image.open("/home/pi/d-text-logo.png")
draw = ImageDraw.Draw(img)

draw.text((10, 60), dbalance, inky_display.BLACK, font)
inky_display.set_image(img)
inky_display.show()

sample logo used

d-text-logo.png.f2786ddf9660d4c99550cfed8056b24c.png

 


Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

If you have a fortunastake (masternode), you could scroll some info on yours, or even cycle through all of them if you have more than 1.

Just chose a random D addy on this one.

editIMG_20190311_005809.thumb.jpg.4b1bee912481c8e4108f14444491371b.jpg

fortuna.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, json

from inky import InkyPHAT

inky_display = InkyPHAT("yellow")
inky_display.set_border(inky_display.YELLOW)

from PIL import Image, ImageFont, ImageDraw

print("""Inky pHAT: Denarius displays blockchain information.
""")

img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)

from font_fredoka_one import FredokaOne

font = ImageFont.truetype(FredokaOne, 18)

daddress = "DSSziJxk6bvz5aX3LyCTQoiHGkXi8RA1bV"
url = "https://www.coinexplorer.net/api/v1/D/masternode?address=%s" % daddress

response = urllib.urlopen(url)
data = json.loads(response.read())

urlbalance = "https://www.coinexplorer.net/api/v1/D/address/balance?address=%s" % daddress

responsebalance = urllib.urlopen(urlbalance)
databalance = json.loads(responsebalance.read())

fs_status = (data['result'][0]['pubkey'] + '\n' + data['result'][0]['status'] + '\n' + data['result'][0]['ip'] + '\n' + databalance['result'][daddress] + "D")

# Load our backdrop image
img = Image.open("/home/pi/fs-logo.png")
draw = ImageDraw.Draw(img)

draw.text((10, 5), fs_status, inky_display.BLACK, font)
inky_display.set_image(img)
inky_display.show()

FS logo attached

fs-logo.png.004ebcada5535da1baed3bfc7f34a82f.png


Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

IMG_20190311_110426.thumb.jpg.d5c632bd5f0beb68354c511717fcf43d.jpg

To change fonts I will use Denarius official font selection of Open Sans - Semibold.

Go to https://github.com/google/fonts/tree/master/apache/opensans

And download https://github.com/google/fonts/blob/master/apache/opensans/OpenSans-SemiBold.ttf

I send files to the PI3 using winscp, and made a directory called fonts to store these. Or you could

cd ~
mkdir fonts
cd fonts
wget https://github.com/google/fonts/blob/master/apache/opensans/OpenSans-SemiBold.ttf
cd ~

If your original line looks like this

font = ImageFont.truetype(FredokaOne, 20)

Change to the new font.

font = ImageFont.truetype("/home/pi/fonts/OpenSans-SemiBold.ttf", 20)

 

  • Like 1

Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

IMG_20190315_101749.thumb.jpg.578ea43393bfea1f213f0df60f9fd7db.jpg

Looks like the image can't be downloaded from here. Not even sure the image can wget from my github. Here is an example of flipping the screen 180 degrees on the pi zero w.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, json

from inky import InkyPHAT

inky_display = InkyPHAT("yellow")
inky_display.set_border(inky_display.WHITE)

from PIL import Image, ImageFont, ImageDraw

print("""Inky pHAT: Denarius displays blockchain information.
""")

img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)

from font_fredoka_one import FredokaOne

#font = ImageFont.truetype("/home/pi/fonts/OpenSans-SemiBold.ttf", 20)
font = ImageFont.truetype(FredokaOne, 20)

url = "http://denarius.win/stats.json"
response = urllib.urlopen(url)
data = json.loads(response.read())
winpow2 = round(data['pow'],3)
winpowresult = float(winpow2) * 100
winpos2 = round(data['pos'],3)
winposresult = float(winpos2) * 100
winblocktime2 = round(data['blocktime'],2)
winpow = ("POW " + str(winpowresult) + "%")
winpos = ("POS " + str(winposresult) + "%")
winblocktime = ("Blocktime: " + str(winblocktime2) + " sec")
winstats = (winpow + winpos + '\n' + winblocktime)

# Load our backdrop image
img = Image.open("/home/pi/d-text-logo.png")
draw = ImageDraw.Draw(img)

#w, h = font.getsize(winstats)
#x = (inky_display.WIDTH / 2) - (w / 2)
#y = (inky_display.HEIGHT / 2) - (h / 2)

draw.text((5, 50), winstats, inky_display.BLACK, font)
flipped = img.rotate(180)
inky_display.set_image(flipped)
inky_display.show()

 


Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

IMG_20190316_015938.thumb.jpg.0d9d2e0e834a02a5352b721c2b7f759a.jpg

Now for a block height and total supply screen.

latest.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import urllib, json

from inky import InkyPHAT

inky_display = InkyPHAT("yellow")
inky_display.set_border(inky_display.WHITE)

from PIL import Image, ImageFont, ImageDraw

print("""Inky pHAT: Denarius displays blockchain information.
""")

img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
draw = ImageDraw.Draw(img)

from font_fredoka_one import FredokaOne

#font = ImageFont.truetype("/home/pi/fonts/OpenSans-SemiBold.ttf", 20)
font = ImageFont.truetype(FredokaOne, 19)

url = "https://www.coinexplorer.net/api/v1/D/block/latest"
response = urllib.urlopen(url)
data = json.loads(response.read())
height = data['result']['height']
heighttext = ("Height: " + str(height))
supply = data['result']['supplyOnBlock']
supplytext = ("Supply: " + str(supply))
stats = (heighttext + '\n' + supplytext)

# Load our backdrop image
img = Image.open("/home/pi/d-text-logo.png")
draw = ImageDraw.Draw(img)

#w, h = font.getsize(winstats)
#x = (inky_display.WIDTH / 2) - (w / 2)
#y = (inky_display.HEIGHT / 2) - (h / 2)

draw.text((5, 55), stats, inky_display.BLACK, font)
flipped = img.rotate(180)
inky_display.set_image(flipped)
inky_display.show()

 


Join Denarius Discord - https://discord.gg/JQEmXwb

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...