Python Bitcoin Mining Profitability Calculator


SUBMITTED BY: Guest

DATE: Nov. 18, 2014, 5:09 a.m.

FORMAT: Python

SIZE: 2.1 kB

HITS: 1841

  1. import requests
  2. import json
  3. from tkinter import *
  4. root = Tk()
  5. root.wm_title("Mining Calc")
  6. diff = StringVar()
  7. hashpower = StringVar()
  8. hashpower.set("100")
  9. hashtype = StringVar()
  10. hashtype.set("GH/s")
  11. btcprice = StringVar()
  12. answer = StringVar()
  13. def calculate(w, x, y, z):
  14. x = float(x)
  15. w = float(w)
  16. z = float(z)
  17. if y == 'H/s':
  18. pass
  19. elif y == 'KH/s':
  20. x = x * 1000
  21. elif y == 'MH/s':
  22. x = (x * 1000) * 1000
  23. elif y == 'GH/s':
  24. x = ((x * 1000) * 1000) * 1000
  25. else:
  26. x = (((x * 1000) * 1000) * 1000) * 1000
  27. mine = ((86400 * x * 25) / ((2**32) * w))
  28. mine = float(mine)
  29. mine = ("%.6f" % mine)
  30. mine = float(mine)
  31. mine_usd = mine * z
  32. mine_usd = ("%.2f" % mine_usd)
  33. labeltext = [mine, ' or ',mine_usd,' USD']
  34. labeltext = ''.join(str(v) for v in labeltext)
  35. answer.set(labeltext)
  36. return
  37. label1 = Label(root, text="Difficulty:")
  38. label1.pack()
  39. difficulty_entry = Entry(root, textvariable=diff)
  40. difficulty_entry.pack()
  41. label2 = Label(root, text="GH/s:")
  42. label2.pack()
  43. hash_entry = Entry(root, textvariable=hashpower)
  44. hash_entry.pack()
  45. label3 = Label(root, text="BTC Price:")
  46. label3.pack()
  47. price_entry = Entry(root, textvariable=btcprice)
  48. price_entry.pack()
  49. label4 = Label(root, text="BTC/day:")
  50. label4.pack()
  51. ans = Entry(root, textvariable=answer)
  52. ans.pack()
  53. hashtype_select = OptionMenu(root, hashtype, "H/s", "KH/s", "MH/s", "GH/s", \
  54. "TH/s")
  55. hashtype_select.pack()
  56. button1 = Button(root, text="Calculate", command= lambda: calculate(diff.get(), hashpower.get(), hashtype.get(), btcprice.get()))
  57. button1.pack()
  58. url = requests.get("https://blockchain.info/stats?format=json").json()
  59. diff.set("%.1f" % (url['difficulty']))
  60. btcprice.set("%.2f" % (url['market_price_usd']))
  61. mainloop()

comments powered by Disqus