Mano savaitgalio projektas

arba hakeriavimo džiaugsmas

Albertas Agejevas

Programuotojų artelė

Problema

Grįžau iš kaimyno 5-ojo gimtadienio.

Kaimyno mama prašo pasidalint!

Kur sudėt? Picasa?

Easy!

Oi...

$ apt-cache search picasa

$ apt-cache search picasa
libgdata1.4-cil - Google GData CLI client library
monodoc-gdata-manual - compiled XML documentation for GData
python-gdata - Google Data Python client library
syncropated - An application for syncing music player playlists with mass storage devices
kipi-plugins - image manipulation/handling plugins for KIPI aware programs
$ apt-cache search picasa
libgdata1.4-cil - Google GData CLI client library
monodoc-gdata-manual - compiled XML documentation for GData
python-gdata - Google Data Python client library
syncropated - An application for syncing music player playlists with mass storage devices
kipi-plugins - image manipulation/handling plugins for KIPI aware programs

Paieškom...

O, malonu

Prabėga 10 minučių...

#!/usr/bin/env python
"""upicasa.py -- an upload script for PicasaWeb"""
import sys
import gdata.photos.service
import gdata.media
import gdata.geo

EMAIL = 'xxxx.xxxx@gmail.com'
PASSWORD = 'XXXXX'

def main():
    gd_client = gdata.photos.service.PhotosService()
    gd_client.email = EMAIL
    gd_client.password = PASSWORD
    gd_client.source = 'alga-upicasa-1'
    print "Authenticating..."
    gd_client.ProgrammaticLogin()

    ...
def main():
    gd_client = gdata.photos.service.PhotosService()
    gd_client.email = EMAIL
    gd_client.password = PASSWORD
    gd_client.source = 'alga-upicasa-1'
    print "Authenticating..."
    gd_client.ProgrammaticLogin()

    album_id = '123123123123132123'
    album_url = '/data/feed/api/user/%s/albumid/%s' % (
        EMAIL, album_id)
    for photo in sys.argv[1:]:
        print "uploading", photo
        photo = gd_client.InsertPhotoSimple(
            album_url, 'New Photo', 
            '', # title 
            photo, content_type='image/jpeg')
    album_id = '123123123123132123'
    album_url = '/data/feed/api/user/%s/albumid/%s' % (
        EMAIL, album_id)
    for photo in sys.argv[1:]:
        print "uploading", photo
        photo = gd_client.InsertPhotoSimple(
            album_url, 'New Photo', 
            '', # title 
            photo, content_type='image/jpeg')


if __name__ == '__main__':
    main()

O iš kur album_id?

    albums = gd_client.GetUserFeed(user=EMAIL)
    for album in albums.entry:
        print 'title: %s, number of photos: %s, id: %s' % (
            album.title.text,
            album.numphotos.text,
            album.gphoto_id.text)

Visi džiaugiasi nuotraukom

Sustokim...

Parašiau apie tai blog postą: http://alga42.blogspot.com/2010/03/sometimes-google-is-great.html.

Prabėga savaitė...

Kitas vaikų gimtadienis!

Reikia pridėt galimybę kurti ir pildyti albumus...

Lukštenam komandinius argumentus...

    import getopt

    options, args = getopt.getopt(sys.argv[1:], "n:a:hl")

    if not options:
        return usage()

    for option, value in options:
        if option == "-n":
            new_album = True
            album_name = value
        elif option == "-a":
            new_album = False
            album_name = value
        elif option == "-h":
            return usage()
        elif option == "-l":
            return list_albums()

Galbūt reikia sukurti albumą...

    if new_album:
        album = gd_client.InsertAlbum(title=album_name,
                                      summary="")
        album_id = album.gphoto_id.text

Gal reikia surasti egizstuojantį

        matches = []
        albums = gd_client.GetUserFeed(
            user=gd_client.email)
        for album in albums.entry:
            if album_name in album.title.text:
                matches.append((album.title.text,
                                album.gphoto_id.text))
        if len(matches) > 1:
            print "More than 1 album matched:"
            for aname, aid in matches:
                print " * %s" % aname
            return
        elif not matches:
            print "No albums matched."
            return
        else:
            album_id = matches[0][1]
            print 'Selected album "%s"' % matches[0][0]

Dar gali praverst išvardinti albumus

    albums = client.GetUserFeed(user=client.email)
    for album in albums.entry:
        print "%s (%s photos)" % (
            album.title.text, album.numphotos.text)

Valio!

Išėjo apie 80 eilučių skriptukas, kuris bent man naudingas

Reikia jį paviešinti!

Pirmiausia ištrauksiu slaptažodį iš kodo

    import getpass
    email = raw_input("Google login: ")
    password = getpass.getpass("Password: ")

Slaptažodį skaitom iš failo

    [google]
    login = xxxxx.yyyyy@gmail.com
    password = Xxxxxxxx
    
    import ConfigParser
    config = ConfigParser.RawConfigParser()
    config.read(password_path)
    email = config.get("google", "login")
    password = config.get("google", "password")

Kaip tai veikia

Kaip tai veikia

Atviro kodo apeigos...



Nepraėjo ir savaitės...

Fan mail!

Hi Albertas,

I wanted to drop you a line to say I love upicasa, and it's working
great for me.  The only issue I had -- which I didn't think was worth
forking/pull-requesting on bitbucket -- was that in upicasa.py:

http://bitbucket.org/alga/upicasa/src/tip/upicasa.py#cl-60

I think both "EMAIL" and "PASSWORD" should be lowercase.

Thanks again for this handy piece of software!  We're using it to
actually upload images made from big computer simulations, and it's
super handy to be able to do this remotely without bringing the images
back, uploading them, etc etc etc.

Best,

Matt

Uždanga!

Dviejų savaitgalių darbelis, sumoj gal 3-4 valandos. Smagu!

Nedidelis pastebėjimas

Mes gyvenam XXI amžiuje

SICP

SICP -- istorija

In 1980, computer engineering was based on starting with clearly-defined things (primitives or small programs) and using them to build larger things that ended up being clearly-defined. Composition of these fragments was the name of the game.

However, nowadays, a real engineer is given a big software library, with a 300-page manual that’s full of errors. He’s also given a robot, whose exact behavior is extremely hard to characterize (what happens when a wheel slips?). The engineer must learn to perform scientific experiments to find out how the software and hardware actually work, at least enough to accomplish the job at hand. Gerry pointed out that we may not like it this way (“because we’re old fogies”), but that’s the way it is, and M.I.T. has to take that into account.

-- http://danweinreb.org/blog/why-did-mit-switch-from-scheme-to-python

Turite klausimų?

Albertas Agejevas <alga@pov.lt>