1

I am looking for a solution (application) that would allow me to make a request to particular web page every x seconds and retrieve the number (the number is the only content there, no html, no xml or anything else) and display this number in the taskbar.

Is there such application out there?

Thank you

2
  • what I don't understand: how is this number to be fetched? where is it stored / displayed? could you give an example? Oct 23, 2014 at 10:22
  • @JacobVlijm the URL probably returns a plain text file without any markup, just the content.
    – muru
    Oct 23, 2014 at 11:22

1 Answer 1

2

The following python snippet should work for you:

#!/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()

Just replace the url, the 2 second delay and the re.search pattern for your needs.

re.search('(.*)', content.read()) should work if your file only contains the number.

The above code displays the total questions on Askubuntu in your taskbar:


                     

Reference: https://unity.ubuntu.com/projects/appindicators/

4
  • 1
    Thank you so much, this really answered my question in much deeper way I could have expected! Brilliant solution! Thanks.
    – Maris
    Oct 23, 2014 at 12:48
  • @Maris: just added a reference link in case you are also interested by a C implementation ;) Oct 23, 2014 at 12:49
  • Thank you, all these programming things are new to me so no idea how C implementation is better than python? Ideally I would love this one to be executed at startup and let it be there for my whole work-session.
    – Maris
    Oct 23, 2014 at 12:51
  • @Maris To run this script at startup, please read How to run scripts on start up Oct 23, 2014 at 13:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .