<s> from . json_search import search <EOL> from . session import Session <EOL> from . import settings <EOL> from . import util <EOL> class _AttractivenessFinder ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , session = None ) : <EOL> self . _session = session or Session . login ( settings . AF_USERNAME , <EOL> settings . AF_PASSWORD ) <EOL> def find_attractiveness ( self , username , accuracy = <NUM_LIT:1000> , <EOL> _lower = <NUM_LIT:0> , _higher = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> average = ( _higher + _lower ) // <NUM_LIT:2> <EOL> if _higher - _lower <= accuracy : <EOL> return average <EOL> results = search ( self . _session , <EOL> count = <NUM_LIT:9> , <EOL> gentation = '<STR_LIT>' , <EOL> keywords = username , <EOL> attractiveness_min = average , <EOL> attractiveness_max = _higher , ) <EOL> found_match = False <EOL> if results : <EOL> for profile in results : <EOL> if profile . username . lower ( ) == username : <EOL> found_match = True <EOL> break <EOL> if found_match : <EOL> return self . find_attractiveness ( username , accuracy , <EOL> average , _higher ) <EOL> else : <EOL> return self . find_attractiveness ( username , accuracy , <EOL> _lower , average ) <EOL> __call__ = find_attractiveness <EOL> class AttractivenessFinderDecorator ( object ) : <EOL> def __init__ ( self , attractiveness_finder = None ) : <EOL> self . _finder = attractiveness_finder or _AttractivenessFinder ( ) <EOL> def __getattr__ ( self , attr ) : <EOL> return getattr ( self . _finder , attr ) <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return self . find_attractiveness ( * args , ** kwargs ) <EOL> class CheckForExistenceAttractivenessFinder ( AttractivenessFinderDecorator ) : <EOL> def _check_for_existence ( self , username ) : <EOL> return bool ( search ( self . _session , <EOL> gentation = '<STR_LIT>' , <EOL> keywords = username , <EOL> count = <NUM_LIT:1> ) ) <EOL> def find_attractiveness ( self , username , * args , ** kwargs ) : <EOL> if self . _check_for_existence ( username ) : <EOL> return self . _finder ( username , * args , ** kwargs ) <EOL> class RoundedAttractivenessFinder ( AttractivenessFinderDecorator ) : <EOL> def find_attractiveness ( self , * args , ** kwargs ) : <EOL> unrounded = self . _finder . find_attractiveness ( * args , ** kwargs ) <EOL> if unrounded is not None : <EOL> return int ( round ( float ( unrounded ) / <NUM_LIT:1000> , <NUM_LIT:0> ) * <NUM_LIT:1000> ) <EOL> class CachedAttractivenessFinder ( AttractivenessFinderDecorator ) : <EOL> def __init__ ( self , attractiveness_finder = None ) : <EOL> self . _finder = attractiveness_finder or _AttractivenessFinder ( ) <EOL> self . _cache = { } <EOL> def find_attractiveness ( self , username , ** kwargs ) : <EOL> if username not in self . _cache : <EOL> self . _cache [ username ] = self . _finder ( username , ** kwargs ) <EOL> return self . _cache [ username ] <EOL> AttractivenessFinder = util . compose ( CachedAttractivenessFinder , <EOL> RoundedAttractivenessFinder , <EOL> CheckForExistenceAttractivenessFinder , <EOL> _AttractivenessFinder ) </s>
