<s> from collections import OrderedDict <EOL> import csv <EOL> import datetime <EOL> import json <EOL> import os <EOL> import requests <EOL> from clerk import maps <EOL> from clerk import utils <EOL> class Case ( object ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . caseid = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . docketid = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . caseissuesid = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . datedecision = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . decisiontype = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . uscite = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . sctcite = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . ledcite = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . lexiscite = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . term = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . naturalcourt = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . chief = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . docket = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . casename = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . dateargument = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . datereargument = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . petitioner = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . petitionerstate = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . respondent = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . respondentstate = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . jurisdiction = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . adminaction = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . adminactionstate = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . threejudgefdc = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . caseorigin = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . caseoriginstate = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . casesource = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . casesourcestate = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . lcdisagreement = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . certreason = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . lcdisposition = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . lcdispositiondirection = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . declarationuncon = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . casedisposition = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . casedispositionunusual = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . partywinning = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . precedentalteration = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . voteunclear = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . issue = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . issuearea = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . decisiondirection = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . decisiondirectiondissent = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . authoritydecision1 = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . authoritydecision2 = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . lawtype = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . lawsupp = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . lawminor = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . majopinwriter = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . majopinassigner = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . splitvote = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . majvotes = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> self . minvotes = kwargs . get ( '<STR_LIT>' , None ) . decode ( '<STR_LIT>' ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT:%s>" % self . case <EOL> def serialize ( self ) : <EOL> return OrderedDict ( ( <EOL> ( '<STR_LIT>' , self . caseid ) , <EOL> ( '<STR_LIT>' , self . docketid ) , <EOL> ( '<STR_LIT>' , self . caseissuesid ) , <EOL> ( '<STR_LIT>' , self . datedecision ) , <EOL> ( '<STR_LIT>' , self . decisiontype ) , <EOL> ( '<STR_LIT>' , self . uscite ) , <EOL> ( '<STR_LIT>' , self . sctcite ) , <EOL> ( '<STR_LIT>' , self . ledcite ) , <EOL> ( '<STR_LIT>' , self . lexiscite ) , <EOL> ( '<STR_LIT>' , self . term ) , <EOL> ( '<STR_LIT>' , self . naturalcourt ) , <EOL> ( '<STR_LIT>' , self . chief ) , <EOL> ( '<STR_LIT>' , self . docket ) , <EOL> ( '<STR_LIT>' , self . casename ) , <EOL> ( '<STR_LIT>' , self . dateargument ) , <EOL> ( '<STR_LIT>' , self . datereargument ) , <EOL> ( '<STR_LIT>' , self . petitioner ) , <EOL> ( '<STR_LIT>' , self . petitionerstate ) , <EOL> ( '<STR_LIT>' , self . respondent ) , <EOL> ( '<STR_LIT>' , self . respondentstate ) , <EOL> ( '<STR_LIT>' , self . jurisdiction ) , <EOL> ( '<STR_LIT>' , self . adminaction ) , <EOL> ( '<STR_LIT>' , self . adminactionstate ) , <EOL> ( '<STR_LIT>' , self . threejudgefdc ) , <EOL> ( '<STR_LIT>' , self . caseorigin ) , <EOL> ( '<STR_LIT>' , self . caseoriginstate ) , <EOL> ( '<STR_LIT>' , self . casesource ) , <EOL> ( '<STR_LIT>' , self . casesourcestate ) , <EOL> ( '<STR_LIT>' , self . lcdisagreement ) , <EOL> ( '<STR_LIT>' , self . certreason ) , <EOL> ( '<STR_LIT>' , self . lcdisposition ) , <EOL> ( '<STR_LIT>' , self . lcdispositiondirection ) , <EOL> ( '<STR_LIT>' , self . declarationuncon ) , <EOL> ( '<STR_LIT>' , self . casedisposition ) , <EOL> ( '<STR_LIT>' , self . casedispositionunusual ) , <EOL> ( '<STR_LIT>' , self . partywinning ) , <EOL> ( '<STR_LIT>' , self . precedentalteration ) , <EOL> ( '<STR_LIT>' , self . voteunclear ) , <EOL> ( '<STR_LIT>' , self . issue ) , <EOL> ( '<STR_LIT>' , self . issuearea ) , <EOL> ( '<STR_LIT>' , self . decisiondirection ) , <EOL> ( '<STR_LIT>' , self . decisiondirectiondissent ) , <EOL> ( '<STR_LIT>' , self . authoritydecision1 ) , <EOL> ( '<STR_LIT>' , self . authoritydecision2 ) , <EOL> ( '<STR_LIT>' , self . lawtype ) , <EOL> ( '<STR_LIT>' , self . lawsupp ) , <EOL> ( '<STR_LIT>' , self . lawminor ) , <EOL> ( '<STR_LIT>' , self . majopinwriter ) , <EOL> ( '<STR_LIT>' , self . majopinassigner ) , <EOL> ( '<STR_LIT>' , self . splitvote ) , <EOL> ( '<STR_LIT>' , self . majvotes ) , <EOL> ( '<STR_LIT>' , self . minvotes ) , <EOL> ) ) <EOL> class Vote ( object ) : <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . caseid = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . docketid = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . caseissuesid = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . voteid = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . datedecision = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . decisiontype = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . uscite = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . sctcite = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . ledcite = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . lexiscite = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . term = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . naturalcourt = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . chief = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . docket = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . casename = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . dateargument = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . datereargument = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . petitioner = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . petitionerstate = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . respondent = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . respondentstate = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . jurisdiction = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . adminaction = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . adminactionstate = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . threejudgefdc = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . caseorigin = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . caseoriginstate = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . casesource = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . casesourcestate = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . lcdisagreement = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . certreason = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . lcdisposition = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . lcdispositiondirection = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . declarationuncon = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . casedisposition = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . casedispositionunusual = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . partywinning = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . precedentalteration = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . voteunclear = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . issue = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . issuearea = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . decisiondirection = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . decisiondirectiondissent = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . authoritydecision1 = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . authoritydecision2 = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . lawtype = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . lawsupp = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . lawminor = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . majopinwriter = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . majopinassigner = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . splitvote = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . majvotes = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . minvotes = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . justice = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . justicename = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . vote = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . opinion = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . direction = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . majority = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . firstagreement = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> self . secondagreement = kwargs [ '<STR_LIT>' ] . decode ( '<STR_LIT>' ) <EOL> def __unicode__ ( self ) : <EOL> return "<STR_LIT>" % ( self . justice , self . case ) <EOL> def serialize ( self ) : <EOL> return OrderedDict ( ( <EOL> ( '<STR_LIT>' , self . caseid ) , <EOL> ( '<STR_LIT>' , self . docketid ) , <EOL> ( '<STR_LIT>' , self . caseissuesid ) , <EOL> ( '<STR_LIT>' , self . voteid ) , <EOL> ( '<STR_LIT>' , self . datedecision ) , <EOL> ( '<STR_LIT>' , self . decisiontype ) , <EOL> ( '<STR_LIT>' , self . uscite ) , <EOL> ( '<STR_LIT>' , self . sctcite ) , <EOL> ( '<STR_LIT>' , self . ledcite ) , <EOL> ( '<STR_LIT>' , self . lexiscite ) , <EOL> ( '<STR_LIT>' , self . term ) , <EOL> ( '<STR_LIT>' , self . naturalcourt ) , <EOL> ( '<STR_LIT>' , self . chief ) , <EOL> ( '<STR_LIT>' , self . docket ) , <EOL> ( '<STR_LIT>' , self . casename ) , <EOL> ( '<STR_LIT>' , self . dateargument ) , <EOL> ( '<STR_LIT>' , self . datereargument ) , <EOL> ( '<STR_LIT>' , self . petitioner ) , <EOL> ( '<STR_LIT>' , self . petitionerstate ) , <EOL> ( '<STR_LIT>' , self . respondent ) , <EOL> ( '<STR_LIT>' , self . respondentstate ) , <EOL> ( '<STR_LIT>' , self . jurisdiction ) , <EOL> ( '<STR_LIT>' , self . adminaction ) , <EOL> ( '<STR_LIT>' , self . adminactionstate ) , <EOL> ( '<STR_LIT>' , self . threejudgefdc ) , <EOL> ( '<STR_LIT>' , self . caseorigin ) , <EOL> ( '<STR_LIT>' , self . caseoriginstate ) , <EOL> ( '<STR_LIT>' , self . casesource ) , <EOL> ( '<STR_LIT>' , self . casesourcestate ) , <EOL> ( '<STR_LIT>' , self . lcdisagreement ) , <EOL> ( '<STR_LIT>' , self . certreason ) , <EOL> ( '<STR_LIT>' , self . lcdisposition ) , <EOL> ( '<STR_LIT>' , self . lcdispositiondirection ) , <EOL> ( '<STR_LIT>' , self . declarationuncon ) , <EOL> ( '<STR_LIT>' , self . casedisposition ) , <EOL> ( '<STR_LIT>' , self . casedispositionunusual ) , <EOL> ( '<STR_LIT>' , self . partywinning ) , <EOL> ( '<STR_LIT>' , self . precedentalteration ) , <EOL> ( '<STR_LIT>' , self . voteunclear ) , <EOL> ( '<STR_LIT>' , self . issue ) , <EOL> ( '<STR_LIT>' , self . issuearea ) , <EOL> ( '<STR_LIT>' , self . decisiondirection ) , <EOL> ( '<STR_LIT>' , self . decisiondirectiondissent ) , <EOL> ( '<STR_LIT>' , self . authoritydecision1 ) , <EOL> ( '<STR_LIT>' , self . authoritydecision2 ) , <EOL> ( '<STR_LIT>' , self . lawtype ) , <EOL> ( '<STR_LIT>' , self . lawsupp ) , <EOL> ( '<STR_LIT>' , self . lawminor ) , <EOL> ( '<STR_LIT>' , self . majopinwriter ) , <EOL> ( '<STR_LIT>' , self . majopinassigner ) , <EOL> ( '<STR_LIT>' , self . splitvote ) , <EOL> ( '<STR_LIT>' , self . majvotes ) , <EOL> ( '<STR_LIT>' , self . minvotes ) , <EOL> ( '<STR_LIT>' , self . justice ) , <EOL> ( '<STR_LIT>' , self . justicename ) , <EOL> ( '<STR_LIT>' , self . vote ) , <EOL> ( '<STR_LIT>' , self . opinion ) , <EOL> ( '<STR_LIT>' , self . direction ) , <EOL> ( '<STR_LIT>' , self . majority ) , <EOL> ( '<STR_LIT>' , self . firstagreement ) , <EOL> ( '<STR_LIT>' , self . secondagreement ) , <EOL> ) ) <EOL> class Load ( object ) : <EOL> DATA_MAP = { <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT:filename>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT:filename>' : '<STR_LIT>' <EOL> } <EOL> } <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . data_directory = kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . votes = [ ] <EOL> self . cases = [ ] <EOL> def download ( self ) : <EOL> for data_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> file_path = '<STR_LIT>' % ( <EOL> self . data_directory , <EOL> self . DATA_MAP [ data_type ] [ '<STR_LIT:filename>' ] <EOL> ) <EOL> if not os . path . isfile ( file_path ) : <EOL> r = requests . get ( self . DATA_MAP [ data_type ] [ '<STR_LIT:url>' ] ) <EOL> with open ( file_path , '<STR_LIT:w>' ) as writefile : <EOL> writefile . write ( r . content ) <EOL> def unzip ( self ) : <EOL> for data_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> file_path = '<STR_LIT>' % ( <EOL> self . data_directory , <EOL> self . DATA_MAP [ data_type ] [ '<STR_LIT:filename>' ] <EOL> ) <EOL> if not os . path . isfile ( file_path ) : <EOL> os . system ( '<STR_LIT>' % ( file_path , self . data_directory ) ) <EOL> def load ( self , data_type ) : <EOL> file_path = '<STR_LIT>' % ( <EOL> self . data_directory , <EOL> self . DATA_MAP [ data_type ] [ '<STR_LIT:filename>' ] <EOL> ) <EOL> if os . path . isfile ( file_path ) : <EOL> with open ( file_path , '<STR_LIT>' ) as readfile : <EOL> if data_type == '<STR_LIT>' : <EOL> self . votes = list ( [ <EOL> Vote ( ** r ) for r in csv . DictReader ( readfile ) <EOL> ] ) <EOL> if data_type == '<STR_LIT>' : <EOL> self . cases = list ( [ <EOL> Case ( ** r ) for r in csv . DictReader ( readfile ) <EOL> ] ) <EOL> def clean ( self ) : <EOL> os . system ( '<STR_LIT>' % <EOL> self . data_directory ) </s>
