loading...
Cover image for Bitcoin price ticker in Gnome desktop

Bitcoin price ticker in Gnome desktop

codesharedot profile image codesharedot ・2 min read

Linux is very extensible. You can change almost anything in the system. Are you using the gnome desktop and interested in crypto?

gnome desktop

Why Gnome? Gnome is the default desktop on Ubuntu, Debian, OpenSUSE and others.

You can create a gnome extension with argos, using Python. You can create a price ticket for bitcoin. But with a price ticker, it needs to update automatically.

gnome extension

How do you do that?

You can name the file like this:

NAME.POSITION.TIME.EXTENSION

For instance

hello.1r.60s.py

Argos will rerun the plugin every 60 seconds.

Get price

To get the price, you can use the requests module and parse JSON data. There are many APIs available for the bitcoin price like kraken, bitstamp and others. We'll use coinmarketcap

#!/usr/bin/env python

import re
from gi.repository import Gio
from datetime import datetime

import time
import json
import requests

def coin():
    data = requests.get('https://api.coinmarketcap.com/v1/ticker/bitcoin/')
    price = data.json()[0]['price_usd']
    btc_price = float(("{0:.2f}").format(float(price))) 
    return btc_price

usd = float(coin())
lastupdate = datetime.now().strftime('%H:%M:%S')

#print("Bitcoin $" + str(usd) + " (" + str(lastupdate) + ") | n 
#iconName=invest-applet")
print("Bitcoin $" + str(usd) + " | iconName=invest-applet")
print("---")
#print("Kraken: $" + str(usd) + " | iconName=gedit bash=gedit  terminal=false")
print("---")

Now save it as bitcoin.1r.60s.py and it will update the price every 60 seconds. There's a lastupdate variable in the code which you can use, or fork it to create your own clock :P

Resources:

Discussion

pic
Editor guide
Collapse
vikramchandra profile image
Vikram Sharma

Hey. Another Ubuntu user here. Recently switched to Ubuntu 18.04. But I am missing the old workspace feature. I also dont like the default behaviour of C+Tab. Nice article. I am trying to come up with a project idea and your article helped me a lot. I also found a tutorial on coin marketcap api. It is a good starting point for people with little or no experience in APIs.