Skip to content

Instantly share code, notes, and snippets.

@caiosba
Created July 5, 2016 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save caiosba/830e6415f840d1f62ae3d9cfc7953ca5 to your computer and use it in GitHub Desktop.
Save caiosba/830e6415f840d1f62ae3d9cfc7953ca5 to your computer and use it in GitHub Desktop.
Ubuntu Unity Indicator to show current dollar value in Brazilian Reais (auto-updates every minute)
#!/usr/bin/env python
# Unity indicator for dolar/real currency
# Author: Caio Almeida <caiosba@gmail.com>
# 05 Jul 2016
import gobject
import gtk
import appindicator
import os, sys
import time
from time import gmtime, strftime
from BeautifulSoup import BeautifulSoup as bs
import urlparse
import urllib2
from urllib import urlretrieve
if __name__ == "__main__":
def update(args=None):
url = 'http://br.investing.com/currencies/usd-brl'
soup = bs(urllib2.urlopen(urllib2.Request(url, headers = { 'User-Agent': 'Mozilla/5.0' })))
value = 'U$ 1 = R$ ' + soup.find('span', { 'id' : 'last_last' }).string
ind.set_label(value)
item.set_label(value)
return True
ind = appindicator.Indicator('dollar-real-client', '', appindicator.CATEGORY_APPLICATION_STATUS)
ind.set_status(appindicator.STATUS_ACTIVE)
ind.set_label('Updating...')
menu = gtk.Menu()
item = gtk.MenuItem('Updating...')
item.show()
menu.append(item)
ind.set_menu(menu)
update()
gtk.timeout_add(60000, update)
gtk.main()
@caiosba
Copy link
Author

caiosba commented Jul 5, 2016

In order to run it, just execute the code above. That's how it looks like:

dollar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment