def getContacts(username, password, type): """ full username, password, and type (yahoo, gmail, etc.) """ prof.start('inviter-get-contacts') proc = subprocess.Popen((const.NotifConst.Inviter.PHP_PATH, const.NotifConst.Inviter.PHP_ARGS, const.NotifConst.Inviter.PATH, type, username), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # SECURITY: Send password to stdin through pipe (out, err) = proc.communicate(password) try: proc.kill() except: pass if out in ('', 'false'): # Probably wrong credentials or provider changed communication parameters return None contacts = [] dict = json.loads(out); for key in dict.keys(): contacts.append((key, dict[key])) prof.stop('inviter-get-contacts') return contacts
def post_to_wall(cookies, body, attachment, to='me'): fb_user = facebook.get_user_from_cookie(cookies, const.FbConst.APP_ID, const.FbConst.APP_SECRET) if fb_user is None: return prof.start('fb-post') graph = facebook.GraphAPI(fb_user['access_token']) body = body.encode('utf8') graph.put_wall_post(body, attachment) prof.stop('fb-post')
def invite(email, extra_data={}): """ Send an invitation to this mail with this extra_data TODO: maybe we should do a bulk operation? """ # Email prof.start('inviter-add') notif = Notif(email=email, type=const.NotifConst.INVITE, extra_data=json.dumps(extra_data)) notif.save() prof.stop('inviter-add')
def receipt(user, type): if 0 == type: # Nothing to update... return try: prof.start('receipt-notif') profile = user.get_profile() # TODO: race condition here? new_notif = profile.notif & ~type if new_notif != profile.notif: profile.notif = new_notif profile.save(force_update=True) except: # TODO: log here raise prof.stop('receipt-notif')
def create(user, type, extra_data={}): # Email notification prof.start('create-notif-email') try: notif = Notif(email=user.email, type=type, extra_data=json.dumps(extra_data)) notif.save() except: # TODO: log here raise prof.stop('create-notif-email') # User notification prof.start('create-notif-user') try: profile = user.get_profile() profile.notif |= type profile.save() except: # TODO: log here raise prof.stop('create-notif-user')