J'y suis
Suffisais de googler un peu et de lire la documentation pour les caractères spéciaux ...
La dernière ligne devient donc
- Code : Tout sélectionner
os.popen("curl -s -L -b cookies.txt -c cookies.txt --data 'wa=wsignin1.0' --data-urlencode 'wresult="+used+"' https://www.myvoo.be/")
En cadeau un app-indicateur écrit pour Ubuntu (mais qui fonctionnne sur tous les bureaux supportant les app-indicators : Kde, Gnome, Xfce, ..)
L’indicateur affiche le pourcentage de la consommation du mois, le nb de Gb utilisé et restant. Il affiche un message d'avertissement quand la consommation dépasse 85%
- Code : Tout sélectionner
#!/usr/bin/env python
import datetime, sys, os
from gi.repository import Gtk, GLib
from gi.repository import AppIndicator3 as appindicator
class vooMeter:
def __init__(self):
# identifier, icon, category
self.indicator = appindicator.Indicator.new("VooMeter", "network", appindicator.IndicatorCategory.SYSTEM_SERVICES)
#seconde option nbr max de carac
self.indicator.set_label("VooMeter", "VooMeter")
self.indicator.set_title("VooMeter")
# need to set this for indicator to be shown
self.indicator.set_status (appindicator.IndicatorStatus.ACTIVE)
# have to give indicator a menu
self.menu = Gtk.Menu()
self.freeM = Gtk.MenuItem("Free :")
self.menu.append(self.freeM)
self.freeM.show()
self.usedM = Gtk.MenuItem("Used :")
self.menu.append(self.usedM)
self.usedM.show()
item = Gtk.MenuItem("Exit")
item.connect("activate", self.handler_menu_exit)
self.menu.append(item)
item.show()
self.menu.show()
self.indicator.set_menu(self.menu)
# Update every 10min
self.warning = True
self.update()
self.warning = False
GLib.timeout_add_seconds(600, self.update)
def handler_menu_exit(self, evt):
os.system("rm /tmp/VooCookie.txt")
Gtk.main_quit()
def update(self):
# check online
if os.system("nm-online -t 2 > /dev/null") == 0:
#connect MyVoo and collect data
os.popen("curl -s -L -b /tmp/VooCookie.txt -c /tmp/VooCookie.txt http://myvoo.voo.be/acces/acces-start.aspl")
os.popen("curl -s -L -b /tmp/VooCookie.txt -c /tmp/VooCookie.txt 'https://sso.voo.be/fr?wa=wsignin1.0&wtrealm=https%3a%2f%2fwww.myvoo.be%2f'")
used = os.popen("curl -s -L -b /tmp/VooCookie.txt -c /tmp/VooCookie.txt --data '[email protected]&Password=YYYYY' 'https://sso.voo.be/fr?wa=wsignin1.0&wtrealm=https%3a%2f%2fwww.myvoo.be%2f'")
used = used.read()
used = used[214:-226]
used = used.replace("<", "<")
used = used.replace(""", "\"")
os.popen("curl -s -L -b /tmp/VooCookie.txt -c /tmp/VooCookie.txt --data 'wa=wsignin1.0' --data-urlencode 'wresult="+used+"' https://www.myvoo.be/")
used = os.popen('curl -s -L -b /tmp/VooCookie.txt -c /tmp/VooCookie.txt https://www.myvoo.be/fr/Usage/Net | grep -m 1 "<li class=\\\"third_li\\\"><span class=\\\"arial_12_403f42\\\">\" | sed s/,/./')
# process data (percent, free, used)
used = used.read()
used = used[67:72]
used = float(used)
#50 is my maximum monthly consumption
percent = (used/50)*100
free = 50 - used
# set new labels
self.indicator.set_title("Voo: "+str(percent)[0:2] +"%")
self.indicator.set_label("Voo: "+str(percent)[0:2] +"%", "Voo: 100%")
self.freeM.set_label("Free: "+str(free)[0:5] +" Gb")
self.usedM.set_label("Used: "+str(used)[0:5] +" Gb")
#Special warning sent once 10min after program start if very high monthly usage)
if percent > 85 and self.warning == False :
os.system("notify-send --hint=int:transient:1 --icon=dialog-warning \"Voo monthly usage is particularly high: "+ str(percent)[0:5] +"% \" \"Free bandwidth remaining: "+ str(free)[0:5] +" Gb\"")
self.warning = True
# False stops timeout
return True
def main(self):
Gtk.main()
if __name__ == "__main__":
indicator = vooMeter()
indicator.main()