Advertisement
aricleather

Python Bitcoin Mining Profitability Calculator

Nov 17th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. import requests
  2. import json
  3. from tkinter import *
  4.  
  5. root = Tk()
  6. root.wm_title("Mining Calc")
  7. diff = StringVar()
  8. hashpower = StringVar()
  9. hashpower.set("100")
  10. hashtype = StringVar()
  11. hashtype.set("GH/s")
  12. btcprice = StringVar()
  13. answer = StringVar()
  14.  
  15. def calculate(w, x, y, z):
  16.     x = float(x)
  17.     w = float(w)
  18.     z = float(z)
  19.     if y == 'H/s':
  20.         pass
  21.     elif y == 'KH/s':
  22.         x = x * 1000
  23.     elif y == 'MH/s':
  24.         x = (x * 1000) * 1000
  25.     elif y == 'GH/s':
  26.         x = ((x * 1000) * 1000) * 1000
  27.     else:
  28.         x = (((x * 1000) * 1000) * 1000) * 1000
  29.     mine = ((86400 * x * 25) / ((2**32) * w))
  30.     mine = float(mine)
  31.     mine = ("%.6f" % mine)
  32.     mine = float(mine)
  33.     mine_usd = mine * z
  34.     mine_usd = ("%.2f" % mine_usd)
  35.     labeltext = [mine, ' or ',mine_usd,' USD']
  36.     labeltext = ''.join(str(v) for v in labeltext)
  37.     answer.set(labeltext)
  38.     return
  39.  
  40. label1 = Label(root, text="Difficulty:")
  41. label1.pack()
  42.  
  43. difficulty_entry = Entry(root, textvariable=diff)
  44. difficulty_entry.pack()
  45.  
  46. label2 = Label(root, text="GH/s:")
  47. label2.pack()
  48.  
  49. hash_entry = Entry(root, textvariable=hashpower)
  50. hash_entry.pack()
  51.  
  52. label3 = Label(root, text="BTC Price:")
  53. label3.pack()
  54.  
  55. price_entry = Entry(root, textvariable=btcprice)
  56. price_entry.pack()
  57.  
  58. label4 = Label(root, text="BTC/day:")
  59. label4.pack()
  60.  
  61. ans = Entry(root, textvariable=answer)
  62. ans.pack()
  63.  
  64. hashtype_select = OptionMenu(root, hashtype, "H/s", "KH/s", "MH/s", "GH/s", \
  65.                              "TH/s")
  66. hashtype_select.pack()
  67.  
  68. button1 = Button(root, text="Calculate", command= lambda: calculate(diff.get(), hashpower.get(), hashtype.get(), btcprice.get()))
  69.                                    
  70. button1.pack()
  71.  
  72. url = requests.get("https://blockchain.info/stats?format=json").json()
  73. diff.set("%.1f" % (url['difficulty']))
  74. btcprice.set("%.2f" % (url['market_price_usd']))
  75.  
  76. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement