<s> from __future__ import print_function <EOL> import json <EOL> from optparse import make_option <EOL> from django . core . management . base import NoArgsCommand , CommandError <EOL> from disqus . api import DisqusClient <EOL> class Command ( NoArgsCommand ) : <EOL> option_list = NoArgsCommand . option_list + ( <EOL> make_option ( '<STR_LIT>' , default = None , dest = '<STR_LIT>' , type = '<STR_LIT:int>' , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , default = '<STR_LIT>' , dest = '<STR_LIT>' , type = '<STR_LIT:str>' , <EOL> help = '<STR_LIT>' ) , <EOL> make_option ( '<STR_LIT>' , default = '<STR_LIT>' , dest = '<STR_LIT>' , type = '<STR_LIT:str>' , <EOL> help = '<STR_LIT>' ) , <EOL> ) <EOL> help = '<STR_LIT>' <EOL> requires_model_validation = False <EOL> def handle ( self , ** options ) : <EOL> from django . conf import settings <EOL> client = DisqusClient ( ) <EOL> indent = options . get ( '<STR_LIT>' ) <EOL> filter_ = options . get ( '<STR_LIT>' ) <EOL> exclude = options . get ( '<STR_LIT>' ) <EOL> forum_list = client . get_forum_list ( user_api_key = settings . DISQUS_API_KEY ) <EOL> try : <EOL> forum = [ f for f in forum_list if f [ '<STR_LIT>' ] == settings . DISQUS_WEBSITE_SHORTNAME ] [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> raise CommandError ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> posts = [ ] <EOL> has_new_posts = True <EOL> start = <NUM_LIT:0> <EOL> step = <NUM_LIT:100> <EOL> while has_new_posts : <EOL> new_posts = client . get_forum_posts ( <EOL> user_api_key = settings . DISQUS_API_KEY , <EOL> forum_id = forum [ '<STR_LIT:id>' ] , <EOL> start = start , <EOL> limit = start + step , <EOL> filter = filter_ , <EOL> exclude = exclude ) <EOL> if not new_posts : <EOL> has_new_posts = False <EOL> else : <EOL> start += step <EOL> posts . append ( new_posts ) <EOL> print ( json . dumps ( posts , indent = indent ) ) </s>
