#NEWLINE# def handle_noargs( self , **options ) : #NEWLINE# #INDENT# if ( not hasattr ( settings , 'JSON_API_URL' ) ) : #NEWLINE# #INDENT# raise CommandError ( 'Required parameter JSON_API_URL not defined in settings.' ) #NEWLINE# #UNINDENT# username = getattr ( settings , 'API_ADMIN_USER' , None ) #NEWLINE# if username : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# user = User . objects . get ( username = username ) #NEWLINE# #UNINDENT# except User . DoesNotExist : #NEWLINE# #INDENT# raise CommandError ( ( 'User with name "%s", specified as settings.API_ADMIN_USER, not found.' % username ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# super_users = User . objects . filter ( is_superuser = True ) #NEWLINE# if super_users . count ( ) : #NEWLINE# #INDENT# user = super_users [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise CommandError ( 'No admin user found.' ) #NEWLINE# #UNINDENT# #UNINDENT# if ( ( not username ) and user ) : #NEWLINE# #INDENT# user_decision = raw_input ( ( 'API_ADMIN_USER is not defined in the settings, using "%s" to get the data from API \nIf you want to use a differnt user specify in the settings.API_ADMIN_USER.\nContinue using "%s" (yes/no): ' % ( user . username , user . username ) ) ) #NEWLINE# if ( user_decision . lower ( ) == 'no' ) : #NEWLINE# #INDENT# raise CommandError ( 'Aborting because you said so.' ) #NEWLINE# #UNINDENT# #UNINDENT# profile = user . get_profile ( ) #NEWLINE# topic = profile . default_topic #NEWLINE# api_data = urllib2 . urlopen ( settings . JSON_API_URL ) . read ( ) #NEWLINE# KEYS_MAPPING = { #NEWLINE# #INDENT# 'title' : 'title' , #NEWLINE# 'description' : 'description' , #NEWLINE# 'url' : 'url' , #NEWLINE# #UNINDENT# } #NEWLINE# "\n        call any custom JSON serizliser/deserializer here \n        as the code assumes the \n        1. title\n        2. text\n        3. story_link \n        keys in the links of the JSON object\n        \n        or update the KEYS_MAPPING dictionary with the correponding attribute names.\n        \n        EX: if 'text' is the name of key for 'description' & \n               'story_link' is the name of key for 'url' then\n            KEYS_MAPPING = {'title': 'title', 'description': 'text', 'url': 'story_link'}\n        " #NEWLINE# json_data = simplejson . loads ( api_data ) #NEWLINE# for link in json_data : #NEWLINE# #INDENT# title = link [ KEYS_MAPPING [ 'title' ] ] #NEWLINE# description = link [ KEYS_MAPPING [ 'description' ] ] #NEWLINE# url = link [ KEYS_MAPPING [ 'url' ] ] #NEWLINE# link_exists = Link . objects . filter ( url = url ) . count ( ) #NEWLINE# if link_exists : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# Link . objects . create_link ( url = url , text = link_exists , user = user , topic = topic , summary = title )