#NEWLINE# def get_outfilename( url , domain = None ) : #NEWLINE# #INDENT# 'Construct the output filename from partial domain and end of path' #NEWLINE# if ( domain is None ) : #NEWLINE# #INDENT# domain = get_domain ( url ) #NEWLINE# #UNINDENT# path = '{url.path}' . format ( url = urlparse ( url ) ) #NEWLINE# if ( '.' in path ) : #NEWLINE# #INDENT# tail_url = path . split ( '.' ) [ ( - 2 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tail_url = path #NEWLINE# #UNINDENT# if tail_url : #NEWLINE# #INDENT# if ( '/' in tail_url ) : #NEWLINE# #INDENT# tail_pieces = [ x for x in tail_url . split ( '/' ) if x ] #NEWLINE# tail_url = tail_pieces [ ( - 1 ) ] #NEWLINE# #UNINDENT# max_len = 24 #NEWLINE# if domain : #NEWLINE# #INDENT# max_len -= ( len ( domain ) + 1 ) #NEWLINE# #UNINDENT# if ( len ( tail_url ) > max_len ) : #NEWLINE# #INDENT# if ( '-' in tail_url ) : #NEWLINE# #INDENT# tail_pieces = [ x for x in tail_url . split ( '-' ) if x ] #NEWLINE# tail_url = tail_pieces . pop ( 0 ) #NEWLINE# if ( len ( tail_url ) > max_len ) : #NEWLINE# #INDENT# tail_url = tail_url [ : max_len ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# tail_len = 0 #NEWLINE# for piece in tail_pieces : #NEWLINE# #INDENT# tail_len += len ( piece ) #NEWLINE# if ( tail_len <= max_len ) : #NEWLINE# #INDENT# tail_url += ( '-' + piece ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# tail_url = tail_url [ : max_len ] #NEWLINE# #UNINDENT# #UNINDENT# if ( not domain ) : #NEWLINE# #INDENT# return tail_url #NEWLINE# #UNINDENT# return '{0}-{1}' . format ( domain , tail_url ) . lower ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return domain . lower ( )