
On this page, i will share python codes that you might find useful.
*If anyone wants to share some python codes, please feel free to contact me. I will credit your shares on this page.
______________________________________________________________________________________________________
Caraka’s btc checker
*Python 3.5
#!/usr/bin/python3
# caraka's btc checker
import urllib.request, json, locale
currencies = ['USD','EUR','GBP','CNY','NZD','CAD']
locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
prices = {}
def btcPrice(code):
with urllib.request.urlopen("http://api.coindesk.com/v1/bpi/currentprice/" + code + ".json") as url:
data = json.loads(url.read().decode())
price = round(float(locale.atof(data['bpi'][code]['rate'])),2)
return price
for currency in currencies:
y = btcPrice(currency)
prices[currency] = y
print("Coindesk BTC:")
print("usd: ${0} eur: €{1} gbp: £{2} cny: ¥{3} nzd: ${4} cad:${5}".format(prices['USD'],prices['EUR'],prices['GBP'],prices['CNY'],prices['NZD'],prices['CAD']))
The above code was made by Caraka from the Demonsaw network. It gives the price in real time of Bitcoin in different currencies. The code can be adapted to any currency. You may find a list here.
PyPing
*Python 3.5
import tkinter as tk
import subprocess
def ping():
cmd = ["ping", entry.get(), "-c", "2"]
output = subprocess.check_output(cmd)
# output = subprocess.check_output("ping {} -c 2".format(entry.get()), shell=True)
print('>', output)
# put result in label
result['text'] = output.decode('utf-8')
my_gui = tk.Tk()
entry = tk.StringVar()
my_gui.geometry('700x400')
my_gui.title("PyPing")
tk.Label(my_gui, text="Enter target IP or host as required.").pack(pady=20)
tk.Entry(my_gui, textvariable=entry).pack(pady=10)
tk.Button(my_gui,text="Ping Test", command=ping).pack(pady=10)
# label for ping result
result = tk.Label(my_gui)
result.pack()
my_gui.mainloop()
Here’s a screen shot with a ping result. The result is printed on a label. You can ping another website and the new result will replace the previous label output. You may want to add things like a menu, but for me, i did not see the need for it since it’s such a small application. GitHub and Stack Overflow are great websites to find good ideas and tutorials to create all kinds of applications. I visit them on a regular basis.
~ teklordz
ColorPicker
import sys
if sys.version[0] == '2': # for Python 3.X or 2.X
from Tkinter import *
from tkColorChooser import askcolor
elif sys.version[0] == '3':
from tkinter import *
from tkinter.colorchooser import askcolor
def setBgColor():
(triple, hexstr) = askcolor()
if hexstr:
print(hexstr)
push.config(bg=hexstr)
show.set("#RRGGBB string = '" + hexstr + "'")
root = Tk()
root.title('ColorPicker')
root.geometry('500x400')
root.resizable(height=FALSE, width=FALSE)
push = Button(root, text='Press to Select Color', command=setBgColor)
push.config(height=3, font=('times', 20, 'bold'))
push.pack(expand=YES, fill=BOTH)
show = StringVar()
show.set('(hex string appears here)')
Entry(root, textvariable=show,
justify=CENTER, font='bold').pack(fill=X)
root.mainloop()
Inspiration for this application was taken from the book “Programming Python, 4th Edition”. Here’s a screenshot.
Links
Contact me
-
Recent Posts
- Teklordz Crypto Report, Sep6, 2018 September 8, 2018
- Bitcoin and the lightning network: Zap wallet review February 22, 2018
- Eijah’s interview, Dec. 27, 2017 December 27, 2017
- Bitfinex is cutting ties with US customers October 17, 2017
- Promether: The end of surveillance September 22, 2017
Archives
Visitors
Donate bitcoin
1AyBELime4qJkwNs5U2cfoRTeu8byYjdqL