<s> import json <EOL> from urllib2 import urlopen <EOL> from django . conf import settings <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from django . core . management . base import CommandError , BaseCommand <EOL> from currencies . models import Currency <EOL> CURRENCY_API_URL = "<STR_LIT>" <EOL> class Command ( BaseCommand ) : <EOL> help = "<STR_LIT>" <EOL> args = "<STR_LIT>" <EOL> def handle ( self , * args , ** options ) : <EOL> print ( "<STR_LIT>" % ( CURRENCY_API_URL ) ) <EOL> currencies = [ ] <EOL> if len ( args ) : <EOL> currencies = list ( args ) <EOL> api = urlopen ( CURRENCY_API_URL ) <EOL> d = json . loads ( api . read ( ) ) <EOL> i = <NUM_LIT:0> <EOL> for currency in sorted ( d . keys ( ) ) : <EOL> if ( not currencies ) or currency in currencies : <EOL> if not Currency . objects . filter ( code = currency ) : <EOL> print ( "<STR_LIT>" % ( d [ currency ] , currency ) ) <EOL> Currency ( code = currency , name = d [ currency ] , factor = <NUM_LIT:1.0> , is_active = False ) . save ( ) <EOL> i += <NUM_LIT:1> <EOL> if i == <NUM_LIT:1> : <EOL> print ( "<STR_LIT>" % ( i ) ) <EOL> else : <EOL> print ( "<STR_LIT>" % ( i ) ) </s>
