def pop_reddits(langs, over18, over18_only, filter_allow_top=False): if not over18: over18_state = 'no_over18' elif over18_only: over18_state = 'only_over18' else: over18_state = 'allow_over18' keys = map(lambda lang: cached_srs_key(lang, over18_state), langs) # dict(lang_key -> [(_downs, allow_top, sr_id)]) srs = g.permacache.get_multi(keys) tups = flatten(srs.values()) if filter_allow_top: # remove the folks that have opted out of being on the front # page as appropriate tups = filter(lambda tpl: tpl[1], tups) if len(srs) > 1: # if there was only one returned, it's already sorted tups.sort(key=lambda tpl: tpl[0], reverse=True) return map(lambda tpl: tpl[2], tups)
def pop_reddits(langs, over18, over18_only, filter_allow_top = False): if not over18: over18_state = 'no_over18' elif over18_only: over18_state = 'only_over18' else: over18_state = 'allow_over18' # we only care about base languages, not subtags here. so en-US -> en unique_langs = [] seen_langs = set() for lang in langs: if '-' in lang: lang = lang.split('-', 1)[0] if lang not in seen_langs: unique_langs.append(lang) seen_langs.add(lang) # dict(lang_key -> [(_downs, allow_top, sr_id)]) bylang = SubredditPopularityByLanguage._byID(unique_langs, properties=[over18_state]) tups = flatten([lang_lists[over18_state] for lang_lists in bylang.values()]) if filter_allow_top: # remove the folks that have opted out of being on the front # page as appropriate tups = filter(lambda tpl: tpl[1], tups) if len(tups) > 1: # if there was only one returned, it's already sorted tups.sort(key = lambda tpl: tpl[0], reverse=True) return map(lambda tpl: tpl[2], tups)
def pop_reddits(langs, over18, over18_only, filter_allow_top = False): if not over18: over18_state = 'no_over18' elif over18_only: over18_state = 'only_over18' else: over18_state = 'allow_over18' keys = map(lambda lang: cached_srs_key(lang, over18_state), langs) # dict(lang_key -> [(_downs, allow_top, sr_id)]) srs = g.permacache.get_multi(keys) tups = flatten(srs.values()) if filter_allow_top: # remove the folks that have opted out of being on the front # page as appropriate tups = filter(lambda tpl: tpl[1], tups) if len(srs) > 1: # if there was only one returned, it's already sorted tups.sort(key = lambda tpl: tpl[0], reverse=True) return map(lambda tpl: tpl[2], tups)
def pop_reddits(langs, over18, over18_only, filter_allow_top = False): if not over18: over18_state = 'no_over18' elif over18_only: over18_state = 'only_over18' else: over18_state = 'allow_over18' # we only care about base languages, not subtags here. so en-US -> en unique_langs = [] seen_langs = set() for lang in langs: if '-' in lang: lang = lang.split('-', 1)[0] if lang not in seen_langs: unique_langs.append(lang) seen_langs.add(lang) keys = map(lambda lang: cached_srs_key(lang, over18_state), unique_langs) # dict(lang_key -> [(_downs, allow_top, sr_id)]) srs = g.permacache.get_multi(keys) tups = flatten(srs.values()) if filter_allow_top: # remove the folks that have opted out of being on the front # page as appropriate tups = filter(lambda tpl: tpl[1], tups) if len(srs) > 1: # if there was only one returned, it's already sorted tups.sort(key = lambda tpl: tpl[0], reverse=True) return map(lambda tpl: tpl[2], tups)
def _fetch(self): CachedQuery._fetch_multi(self.queries) self.data = flatten([q.data for q in self.queries])