Tuesday, October 25, 2011

The python module : spynner

On official site we see the description of the spynner module :
Spynner is a stateful programmatic web browser module for Python with Javascript/AJAX support based upon the QtWebKit framework.
The module is esay to use. With few lines of codes you can use this module to parse ,view and use web pages.
from __future__ import division
from __future__ import unicode_literals
from __future__ import print_function
import re
import spynner
from BeautifulSoup import BeautifulSoup
import time
br = spynner.Browser()
br.fill("input[name=username]", "name")
br.fill("input[name=passwd]", "pass")

The result is show in the image bellow:
The source code is not complete. I make this simple example just to show us how to fill some editbox.
If you wantthen you can develop this script and make more useful.
I wait your answers with source code additions and new ways of using this python module.

Saturday, October 1, 2011

Show photo albums and storage with python and gdata module

The example i show today has tow parts.
First I use module getpass and i connect to google user account.
Next I use gdata functions to print user albums and spending storage.
You can also use the gdata module to add comments, rotate photos, add photos ...
The code source is show bellow:
import getpass
import gdata.photos, gdata.photos.service
pws = gdata.photos.service.PhotosService()
username=raw_input("username - ")
password= getpass.getpass("password - ")

pws.ClientLogin(username, password)

#get all albums from account
userfeed_albums = pws.GetUserFeed(kind='album')

#print albums
print "User %s has these albums: %s" % (userfeed_albums.user.text,
[a.title.text for a in userfeed_albums.entry])

#print storage
print "%s is spending %s-Mb on storage" % \
(userfeed_albums.nickname.text, int(userfeed_albums.quotacurrent.text)/1024/1024)