#NEWLINE# def handle( self , **options ) : #NEWLINE# #INDENT# current_site = Site . objects . get_current ( ) #NEWLINE# client = DisqusClient ( ) #NEWLINE# verbosity = int ( options . get ( 'verbosity' ) ) #NEWLINE# dry_run = bool ( options . get ( 'dry_run' ) ) #NEWLINE# state_file = options . get ( 'state_file' ) #NEWLINE# last_exported_id = None #NEWLINE# if ( ( state_file is not None ) and os . path . exists ( state_file ) ) : #NEWLINE# #INDENT# last_exported_id = self . _get_last_state ( state_file ) #NEWLINE# #UNINDENT# comments = self . _get_comments_to_export ( last_exported_id ) #NEWLINE# comments_count = comments . count ( ) #NEWLINE# if ( verbosity >= 1 ) : #NEWLINE# #INDENT# print ( ( 'Exporting %d comment(s)' % comments_count ) ) #NEWLINE# #UNINDENT# if dry_run : #NEWLINE# #INDENT# print ( ( '%s' % ( comments , ) ) ) #NEWLINE# return #NEWLINE# #UNINDENT# if ( not comments_count ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# forum_list = client . get_forum_list ( user_api_key = settings . DISQUS_API_KEY ) #NEWLINE# try : #NEWLINE# #INDENT# forum = [ f for f in forum_list if ( comments [ 'shortname' ] == settings . DISQUS_WEBSITE_SHORTNAME ) ] [ 0 ] #NEWLINE# #UNINDENT# except IndexError : #NEWLINE# #INDENT# raise CommandError ( ( ( 'Could not find forum. ' + 'Please check your ' ) + "'DISQUS_WEBSITE_SHORTNAME' setting." ) ) #NEWLINE# #UNINDENT# forum_api_key = client . get_forum_api_key ( user_api_key = settings . DISQUS_API_KEY , forum_id = forum [ 'id' ] ) #NEWLINE# for comment in comments : #NEWLINE# #INDENT# if ( verbosity >= 1 ) : #NEWLINE# #INDENT# print ( ( "Exporting comment '%s'" % comment ) ) #NEWLINE# #UNINDENT# url = ( 'http://%s%s' % ( current_site . domain , comment . content_object . get_absolute_url ( ) ) ) #NEWLINE# thread = client . get_thread_by_url ( url = url , forum_api_key = forum_api_key ) #NEWLINE# if ( not thread ) : #NEWLINE# #INDENT# thread = client . thread_by_identifier ( forum_api_key = forum_api_key , identifier = force_text ( comment . content_object ) , title = force_text ( comment . content_object ) ) [ 'thread' ] #NEWLINE# client . update_thread ( forum_api_key = forum_api_key , thread_id = thread [ 'id' ] , url = url ) #NEWLINE# #UNINDENT# client . create_post ( forum_api_key = forum_api_key , thread_id = thread [ 'id' ] , message = comment . comment . encode ( 'utf-8' ) , author_name = comment . userinfo . get ( 'name' , 'nobody' ) . encode ( 'utf-8' ) , author_email = comment . userinfo . get ( 'email' , 'nobody@example.org' ) , author_url = comment . userinfo . get ( 'url' , '' ) , created_at = comment . submit_date . strftime ( '%Y-%m-%dT%H:%M' ) ) #NEWLINE# if ( state_file is not None ) : #NEWLINE# #INDENT# self . _save_state ( state_file , comment . pk )