<s> from django . core . management . base import BaseCommand , CommandError <EOL> import os <EOL> from datetime import date <EOL> from tax . modules . us_sst . models import TaxRate <EOL> from decimal import Decimal <EOL> class Command ( BaseCommand ) : <EOL> '''<STR_LIT>''' <EOL> help = "<STR_LIT>" <EOL> args = '<STR_LIT:file>' <EOL> def handle ( self , * args , ** options ) : <EOL> new = <NUM_LIT:0> <EOL> updated = <NUM_LIT:0> <EOL> unchanged = <NUM_LIT:0> <EOL> if not args : <EOL> raise CommandError ( "<STR_LIT>" ) <EOL> file = args [ <NUM_LIT:0> ] <EOL> if not os . path . isfile ( file ) : <EOL> raise RuntimeError ( "<STR_LIT>" % file ) <EOL> file = open ( file ) <EOL> for line in file : <EOL> ( state , type , code , rate_intra , rate_inter , food_intra , food_inter , <EOL> start , end ) = line . split ( '<STR_LIT:U+002C>' ) <EOL> state = int ( state ) <EOL> start = date ( int ( start [ <NUM_LIT:0> : <NUM_LIT:4> ] ) , int ( start [ <NUM_LIT:4> : <NUM_LIT:6> ] ) , int ( start [ <NUM_LIT:6> : <NUM_LIT:9> ] ) ) <EOL> end = date ( int ( end [ <NUM_LIT:0> : <NUM_LIT:4> ] ) , int ( end [ <NUM_LIT:4> : <NUM_LIT:6> ] ) , int ( end [ <NUM_LIT:6> : <NUM_LIT:9> ] ) ) <EOL> try : <EOL> tr = TaxRate . objects . get ( <EOL> state = state , <EOL> jurisdictionType = type , <EOL> jurisdictionFipsCode = code , <EOL> startDate = start , <EOL> ) <EOL> if tr . endDate != end : <EOL> tr . endDate = end <EOL> tr . save ( ) <EOL> updated += <NUM_LIT:1> <EOL> else : <EOL> unchanged += <NUM_LIT:1> <EOL> except TaxRate . DoesNotExist : <EOL> TaxRate ( <EOL> state = state , <EOL> jurisdictionType = type , <EOL> jurisdictionFipsCode = code , <EOL> startDate = start , <EOL> endDate = end , <EOL> generalRateIntrastate = Decimal ( rate_intra ) , <EOL> generalRateInterstate = Decimal ( rate_inter ) , <EOL> foodRateIntrastate = Decimal ( food_intra ) , <EOL> foodRateInterstate = Decimal ( food_inter ) , <EOL> ) . save ( ) <EOL> new += <NUM_LIT:1> <EOL> print "<STR_LIT>" % ( new , updated , unchanged ) </s>
