def select_album(album_id): user = users.get_current_user() album_list = AlbumList.get_for_user(user) the_album = None for album in album_list: if album['gphoto$id']['$t'] == album_id: the_album = album break if not album: return 'album not found' email_address = md5.new(os.urandom(25)).hexdigest() # if it's taken, generate new while AlbumEmailMapping.all().filter('email_address = ', email_address) \ .count() > 0: email_address = md5.new(os.urandom(25)).hexdigest() mapping = AlbumEmailMapping( owner=user, email_address=email_address, album=album) mapping.put() return redirect(url_for('list_albums'))
def home(): user = users.get_current_user() credentials = None mappings = None if user: credentials = UserCredential.get_by_user(user) mappings = AlbumEmailMapping.all().filter('owner =', user) return render_template('home.html', user=user, credentials=credentials, mappings=mappings)
def process_email(emailid): #get email email = UnprocessedEmail.get_by_id(emailid) email_key = email.to_address.split('@')[0] # find mapping mapping = AlbumEmailMapping.all().filter('email_address =', email_key) \ .get() if not mapping: logging.info('mapping not found: %s' % email_key) return # get credential credential = UserCredential.get_by_user(mapping.owner) if not credential: logging.info('No credential found for user %s, cannot upload.' % mapping.owner) return # gotta grab url. check links on album data url = None for link in mapping.album['link']: if link['rel'] == 'http://schemas.google.com/g/2005#feed': url = link['href'].split('?alt')[0] if not url: logging.info('couldn\'t find feed url') return logging.info('here\s my uri!: %s' % url) h = httplib2.Http() h = credential.authorize(h) for key in email.attachment_keys: blobinfo = blobstore.BlobInfo.get(key) value = blobstore.BlobReader(blobinfo).read() response = h.request(url, method="POST", headers={ 'Content-Type': blobinfo.content_type, 'Content-Length': str(blobinfo.size) }, body=value) logging.info('posted some shit, see the response:') logging.info(response) UserCredential.set_credentials_for_user(mapping.owner, credential) # clean up blobinfo.delete() email.delete()
def process_email(emailid): #get email email = UnprocessedEmail.get_by_id(emailid) email_key = email.to_address.split('@')[0] # find mapping mapping = AlbumEmailMapping.all().filter('email_address =', email_key) \ .get() if not mapping: logging.info('mapping not found: %s' % email_key) return # get credential credential = UserCredential.get_by_user(mapping.owner) if not credential: logging.info('No credential found for user %s, cannot upload.' % mapping.owner) return # gotta grab url. check links on album data url = None for link in mapping.album['link']: if link['rel'] == 'http://schemas.google.com/g/2005#feed': url = link['href'].split('?alt')[0] if not url: logging.info('couldn\'t find feed url') return logging.info('here\s my uri!: %s' % url) h = httplib2.Http() h = credential.authorize(h) for key in email.attachment_keys: blobinfo = blobstore.BlobInfo.get(key) value = blobstore.BlobReader(blobinfo).read() response = h.request(url, method="POST", headers={ 'Content-Type': blobinfo.content_type, 'Content-Length': str(blobinfo.size)}, body=value) logging.info('posted some shit, see the response:') logging.info(response) UserCredential.set_credentials_for_user(mapping.owner, credential) # clean up blobinfo.delete() email.delete()
def list_albums(): user = users.get_current_user() if 'refresh' in request.args: AlbumList.delete_for_user(user) return redirect(url_for('list_albums')) album_list = AlbumList.get_for_user(user) album_mappings = dict() # key=albumid, value=mapping for mapping in AlbumEmailMapping.all().filter('owner =', user): # this is a mapping. album_id = mapping.album['gphoto$id']['$t'] logging.info('adding album with id %s to map.' % album_id) album_mappings[album_id] = mapping return render_template('albums.html', user=user, album_list=album_list, album_mappings=album_mappings)