Page 1 sur 1

Connection automatisée MyVoo

Message Publié : 04 Déc 2012 10:26
par JoVoo
Bonjour, je cherche à récupérer de façon automatisé ma consommation internet du mois.
Pour cela j'écris un petit script utilisant cURL. Malheureusement je n'arrive pas à le finir.
Quelqu'un a-t'il déjà réussit a se connecter de façon automatisé sur myVoo?

Voici le code que j'utilise (la dernière instruction est visiblement fausse):
Code : Tout sélectionner
os.popen("curl -s -L -b cookies.txt -c cookies.txt http://myvoo.voo.be/acces/acces-start.aspl")
os.popen("curl -s -L -b cookies.txt -c cookies.txt 'https://sso.voo.be/fr?wa=wsignin1.0&wtrealm=https%3a%2f%2fwww.myvoo.be%2f'")
used = os.popen("curl -s -L -b cookies.txt -c cookies.txt --data 'UserName=XXXXX&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("&lt;", "<")
used = used.replace("&quot;", "\"")
os.popen("curl -s -L -b cookies.txt -c cookies.txt --data 'wa=wsignin1.0&wresult="+used+"' https://www.myvoo.be/ > ~/test.html")

Bien à vous
Jo

Message Publié : 05 Déc 2012 10:10
par JoVoo
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("&lt;", "<")
      used = used.replace("&quot;", "\"")

      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()

Message Publié : 05 Déc 2012 21:57
par gaetanbri
ce a l'air sympa, mais on fait comment ???

Message Publié : 06 Déc 2012 10:09
par JoVoo
Il faut sauver le code dans un fichier avec une extension .py (par ex : voo.py)

Dans la ligne
Code : Tout sélectionner
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'")

Il faut remplacer [email protected] par son identifiant, et YYYY par son mot de passe (Le code ne fonctionne pas actuellement pour les mots de passe ou les identifiants comprennant des caractères spéciaux : =><&"' )

Puis il faut rendre le code exécutable : pour cela faire un click droit sur le fichier et dans propriétés -> permission cocher "permettre l'exécution de ce fichier"

Après ça il suffit de de doubler clicker sur le fichier et de le lancer

Après quelques secondes vous devriez voir ceci dans votre barre de notification :
Image

Il aussi faut que curl et gtk soient installés sur l'ordinateur.