def get_profiles(prev_run_timestamp, categories, site): """Get the profiles needed for the script to run. Parameters: prev_run_timestamp : a string containing a MediaWiki- formatted timestamp denoting the last run of the bot categories : the 'categories' dictionary from the config file site : a mwclient Site object Returns: new_profiles : a list of dicts with information about profiles newly added to the categories listed under "skills" and "topics" in the config file opted_out_profiles : a list of dicts with information about all opted-out members' profiles """ opted_out_profiles = mbapi.get_all_category_members( categories['people']['optout'], site) all_categories = (categories['people']['skills'] + categories['people']['topics']) new_profiles = [] for category in all_categories: new_profiles = new_profiles + mbapi.get_new_members(category, site, prev_run_timestamp) return (new_profiles, opted_out_profiles)
def get_ideas_by_category(ideas, interests, skills, site, categories): """Create a dict of lists of ideas, keyed by the topic or skill category. Employs lazy loading to only fetch the ideas in the skill and interest categories provided. Parameters: ideas : a dict of ideas, empty or previously returned by this method interests : a list of interest categories (topics) skills : a list of skill categories site : a mwclient Site object categories : the category dict from the config Returns: A dict of lists of ideas with the following structure: ideas = {topic1: [{profile: <idea profile page title>, profile_id: <idea profile page id>}, ...], skill1: [...], skill2: [...], ... } """ interest_dict = {k: v for k, v in zip(categories['people']['topics'], categories['ideas']['topics'])} skill_dict = {k: v for k, v in zip(categories['people']['skills'], categories['ideas']['skills'])} idea_interests = [interest_dict.get(interest) for interest in interests] idea_skills = [skill_dict.get(skill) for skill in skills] # Lazy loading of ideas by skill and interest for interest in idea_interests: if interest not in ideas: ideas[interest] = mbapi.get_all_category_members(interest, site) else: pass for skill in idea_skills: if skill not in ideas: ideas[skill] = mbapi.get_all_category_members(skill, site) else: pass if not interests and not skills and 'all' not in ideas: ideas['all'] = mbapi.get_all_category_members( categories['ideas']['all'], site) else: pass # Figure out which ideas are relevant to return ideas_list = [] if interests and skills: for idea_interest in idea_interests: for idea_skill in idea_skills: filtered_ideas = [x for x in ideas[idea_skill] if x in ideas[idea_interest] and x not in ideas_list] ideas_list.extend(filtered_ideas) elif interests: for idea_interest in idea_interests: filtered_ideas = [x for x in ideas[idea_interest] if x not in ideas_list] ideas_list.extend(filtered_ideas) elif skills: for idea_skill in idea_skills: filtered_ideas = [x for x in ideas[idea_skill] if x not in ideas_list] ideas_list.extend(filtered_ideas) else: ideas_list = ideas['all'] return ideas_list