O snippet de python a seguir deve funcionar para você:
#!/usr/bin/env python
import re
import sys
import urllib2
from gi.repository import Gtk, GLib
from gi.repository import AppIndicator3 as appindicator
class MyIndicator:
def __init__(self):
# Create Indicator with icon and label
icon_image = "/usr/share/unity/icons/panel-shadow.png"
self.ind = appindicator.Indicator.new(
"MagicNumber",
icon_image,
appindicator.IndicatorCategory.APPLICATION_STATUS
)
self.ind.set_status(appindicator.IndicatorStatus.ACTIVE)
self.menu_structure()
# Menu structure
def menu_structure(self):
# GTK menu
self.menu = Gtk.Menu()
self.exit = Gtk.MenuItem("Exit")
self.exit.connect("activate", self.quit)
self.exit.show()
self.menu.append(self.exit)
self.ind.set_menu(self.menu)
content = urllib2.urlopen('http://askubuntu.com/questions')
questions = re.search('<div class="summarycount al">(.*?)</div>', content.read())
self.ind.set_label(str(questions.group(1)), "")
GLib.timeout_add_seconds(2,self.menu_structure)
def quit(self, widget):
sys.exit(0)
if __name__ == "__main__":
indicator = MyIndicator()
Gtk.main()
Basta substituir o url
, o 2
second delay e o re.search
padrão de acordo com suas necessidades.
re.search('(.*)', content.read())
deve funcionar se o seu arquivo contiver apenas o número.
O código acima mostra o total de perguntas no Askubuntu na sua barra de tarefas:
Referência: link