def finish_auth(): if 'error' in request.args: return 'You must grant access for this to work, silly' if 'code' in request.args: # auth success, retrieve flow then build and stash credentials. flow = memcache.get('flow:%s' % users.get_current_user().user_id()) credentials = flow.step2_exchange(request.args['code']) UserCredential.set_credentials_for_user(users.get_current_user(), credentials) return redirect(url_for('home'))
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()