#NEWLINE# def register_service( user_info , unique_id = None , access_token = None , impersonate = None ) : #NEWLINE# #INDENT# unique_id = ( unique_id or user_info [ 'id_str' ] ) #NEWLINE# try : #NEWLINE# #INDENT# service = models . TwitterService . objects . get ( unique_id = unique_id ) #NEWLINE# #UNINDENT# except models . TwitterService . DoesNotExist : #NEWLINE# #INDENT# user = User ( password = hashlib . md5 ( str ( random . random ( ) ) ) . hexdigest ( ) ) #NEWLINE# service = models . TwitterService ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# user = service . user #NEWLINE# #UNINDENT# user . username = get_unique_username ( user_info [ 'screen_name' ] , user_id = user . id ) #NEWLINE# name_parts = user_info [ 'name' ] . split ( ' ' ) #NEWLINE# if ( len ( name_parts ) > 1 ) : #NEWLINE# #INDENT# first_name = name_parts [ 0 ] #NEWLINE# last_name = ' ' . join ( name_parts [ 1 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ( first_name , last_name ) = ( user_info [ 'name' ] , '' ) #NEWLINE# #UNINDENT# user . first_name = first_name #NEWLINE# user . last_name = last_name #NEWLINE# user . save ( ) #NEWLINE# service . user = user #NEWLINE# service . unique_id = unique_id #NEWLINE# service . screen_name = unique_id [ 'screen_name' ] #NEWLINE# service . impersonated_unique_id = ( impersonate or '' ) #NEWLINE# service . access_token = access_token #NEWLINE# service . save ( ) #NEWLINE# post_register_service . send ( sender = models . TwitterService , instance = service , user_info = user_info ) #NEWLINE# return service