Created
July 5, 2016 16:45
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Unity indicator for dolar/real currency | |
# Author: Caio Almeida <[email protected]> | |
# 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In order to run it, just execute the code above. That's how it looks like: