buzzkillb

Untitled

Mar 15th, 2019
103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import urllib, json
  5.  
  6. from inky import InkyPHAT
  7.  
  8. inky_display = InkyPHAT("yellow")
  9. inky_display.set_border(inky_display.WHITE)
  10.  
  11. from PIL import Image, ImageFont, ImageDraw
  12.  
  13. print("""Inky pHAT: Denarius displays blockchain information.
  14. """)
  15.  
  16. img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
  17. draw = ImageDraw.Draw(img)
  18.  
  19. from font_fredoka_one import FredokaOne
  20.  
  21. font = ImageFont.truetype("/home/pi/fonts/OpenSans-SemiBold.ttf", 20)
  22. #font = ImageFont.truetype(FredokaOne, 20)
  23.  
  24. url = "http://denarius.win/stats.json"
  25. response = urllib.urlopen(url)
  26. data = json.loads(response.read())
  27. winpow2 = round(data['pow'],3)
  28. winpowresult = float(winpow2) * 100
  29. winpos2 = round(data['pos'],3)
  30. winposresult = float(winpos2) * 100
  31. winblocktime2 = round(data['blocktime'],2)
  32. winpow = ("POW " + str(winpowresult) + "%")
  33. winpos = ("POS " + str(winposresult) + "%")
  34. winblocktime = ("Blocktime: " + str(winblocktime2) + " sec")
  35. winstats = (winpow + winpos + '\n' + winblocktime)
  36.  
  37. # Load our backdrop image
  38. img = Image.open("/home/pi/d-text-logo.png")
  39. draw = ImageDraw.Draw(img)
  40.  
  41. #w, h = font.getsize(winstats)
  42. #x = (inky_display.WIDTH / 2) - (w / 2)
  43. #y = (inky_display.HEIGHT / 2) - (h / 2)
  44.  
  45. draw.text((5, 50), winstats, inky_display.BLACK, font)
  46. inky_display.set_image(img)
  47. inky_display.show()
RAW Paste Data