<s> from datetime import datetime <EOL> import functools <EOL> from openelex . lib . text import slugify <EOL> def build_github_url ( state , generated_filename ) : <EOL> """<STR_LIT>""" <EOL> tpl = "<STR_LIT>" <EOL> return tpl . format ( state . lower ( ) , generated_filename ) <EOL> def build_raw_github_url ( state , datestring , raw_filename ) : <EOL> """<STR_LIT>""" <EOL> tpl = "<STR_LIT>" <EOL> return tpl . format ( state . lower ( ) , datestring , raw_filename ) <EOL> def standardized_filename ( state , start_date , extension , <EOL> party = None , special = False , race_type = None , reporting_level = None , <EOL> jurisdiction = None , office = None , office_district = None , <EOL> prefix_bits = [ ] , suffix_bits = [ ] , sep = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> bits = [ ] <EOL> bits . extend ( prefix_bits ) <EOL> bits . extend ( [ <EOL> start_date . replace ( '<STR_LIT:->' , '<STR_LIT>' ) , <EOL> state . lower ( ) , <EOL> ] ) <EOL> if special : <EOL> bits . append ( '<STR_LIT>' ) <EOL> if party : <EOL> bits . append ( slugify ( party ) ) <EOL> if race_type : <EOL> bits . append ( race_type . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) ) <EOL> if jurisdiction : <EOL> bits . append ( slugify ( jurisdiction ) ) <EOL> if office : <EOL> bits . append ( slugify ( office ) ) <EOL> if office_district : <EOL> bits . append ( slugify ( office_district ) ) <EOL> if reporting_level : <EOL> bits . append ( reporting_level ) <EOL> bits . extend ( suffix_bits ) <EOL> return sep . join ( bits ) + extension <EOL> def format_date ( datestr ) : <EOL> """<STR_LIT>""" <EOL> datefilter_formats = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> for infmt , outfmt in datefilter_formats . items ( ) : <EOL> try : <EOL> return datetime . strptime ( datestr , infmt ) . strftime ( outfmt ) <EOL> except ValueError : <EOL> pass <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" . format ( datestr ) ) <EOL> def compose ( * functions ) : <EOL> """<STR_LIT>""" <EOL> def compose2 ( f , g ) : <EOL> return lambda x : f ( g ( x ) ) <EOL> return functools . reduce ( compose2 , functions ) </s>
