Back to my blog Back to my projects

Scripts

Changeset fc7bbfc


Ignore:
Timestamp:
02/24/12 08:50:43 (2 years ago)
Author:
Aurélien Bompard <aurelien@…>
Branches:
master
Children:
d949443
Parents:
45222ed
git-author:
Aurélien Bompard <aurelien@…> (02/24/12 08:50:43)
git-committer:
Aurélien Bompard <aurelien@…> (02/24/12 08:50:43)
Message:

gmail-contacts-to-vcf: add an option to save profile pictures

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gmail-contacts-to-vcf.py

    rd473bae rfc7bbfc  
    3939class Contacts(object): 
    4040 
    41     def __init__(self, email, password): 
     41    def __init__(self, email, password, picsdir=None): 
    4242        """ 
    4343        Takes an email and password corresponding to a gmail account to 
     
    5353        self.groups = {} 
    5454        self.maingroup = None 
     55        self.picsdir = picsdir 
     56        if self.picsdir and not os.path.exists(self.picsdir): 
     57            os.makedirs(self.picsdir) 
    5558 
    5659 
     
    173176                contact.photo.encoding_param = "b" 
    174177                contact.photo.type_param = "image/jpeg" 
    175             #with open("%s.jpg" % entry.title.text, "w") as img: 
    176             #    img.write(hosted_image_binary) 
     178            if self.picsdir: 
     179                with open(os.path.join(self.picsdir, 
     180                          "%s.jpg" % entry.title.text), "w") as img: 
     181                    img.write(hosted_image_binary) 
    177182 
    178183        # IM 
     
    223228    parser.add_option("-p", "--password") 
    224229    parser.add_option("-f", "--filename", help="VCard file to write to") 
     230    parser.add_option("--pics", help="dump contact pictures in this folder") 
    225231    opts, args = parser.parse_args() 
    226232    while not opts.user: 
     
    240246 
    241247    try: 
    242         contacts = Contacts(opts.user, opts.password) 
     248        contacts = Contacts(opts.user, opts.password, opts.pics) 
    243249    except gdata.service.BadAuthentication: 
    244250        print 'Invalid user credentials given.' 
Note: See TracChangeset for help on using the changeset viewer.