-
Notifications
You must be signed in to change notification settings - Fork 4
/
picasa.py
63 lines (56 loc) · 2.15 KB
/
picasa.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/python
###
# This script serves to upload the pictures from the specified directory to the specified album in picasa.
# Usage : python picasaUploader -l <source directory>
###
import gdata.photos.service
import gdata.media
import gdata.geo
import re
import globals
'''
Function takes in filename,title,username and password
uploads the given photo to the account
and returns the url of that photo
'''
def post_to_picasa(filename,photo_title,username=None,password=None):
gd_client = gdata.photos.service.PhotosService()
#UI should be called and parameters passed!
if globals.picasa_username is None or globals.picasa_password is None:
# call UI .. set the username and password
# Store them in globals.youtube_*
# just in case, its taken as func arguments now
globals.picasa_username = username
globals.picasa_password = password
gd_client.email = globals.picasa_username #type your username here
gd_client.password = globals.picasa_password # store your password in an environment variable called PASSWD
gd_client.source = 'python uploader'
try:
gd_client.ProgrammaticLogin()
except:
raise 'Could not authenticate the user'
return 0
username=gd_client.email
index = 0
try:
album = gd_client.InsertAlbum(title=photo_title, summary='Uploaded from EasyShare')
except:
raise 'Could not create Album'
return 0
album_url = '/data/feed/api/user/%s/albumid/%s' %(username,album.gphoto_id.text)
try:
photo = gd_client.InsertPhotoSimple(album_url,photo_title,'Uploaded from EasyShare',filename,content_type='image/jpeg')
except :
raise 'Error uploading photo'
return 0
try:
res = re.search("href=\"(.*?)\"",str(photo.GetHtmlLink()),0)
if res.group(1) is not None:
return res.group(1)
else:
raise 'Could not extract link'
return 0
except:
raise 'Error in reg ex'
return 0
#print post_to_picasa(filename = '/home/pali/Pictures/ubu.jpg', photo_title='Ubuntu', username = 'kartalkhan', password = 'kartalkhanAjja')