Exemple #1
0
def get_all_members() -> List[dict]:
    """Returns a list of dicts of member data.
    """
    rows = sheetdata.find_rows(_S.member, matcher=None)
    # Putting "||" between the first and last name to get a proper sort is not great, but sufficient
    rows.sort(key=lambda r: str.lower(
        f'{r.dict[_S.member.fields.last_name.name]}||{r.dict[_S.member.fields.first_name.name]}'
    ))
    return [r.dict for r in rows]
Exemple #2
0
def _get_members_renewed_ago(
        after_datetime: Optional[datetime.datetime],
        before_datetime: Optional[datetime.datetime]) -> List[sheetdata.Row]:
    """Get the members who were last renewed within the given window.
    Args:
        after_datetime (datetime): Members must have been renewed *after* this
            date. Optional.
        before_datetime (datetime): Members must have been renewed *before*
            this date. Optional.
    Returns:
        List of member rows.
    """

    # Note that dates get returned from the spreadsheet as locale-formatted
    # strings, so we can't do a list-feed query to get just the rows we want.
    # Instead we're going to have to go through the whole set and filter them
    # from there.

    assert after_datetime or before_datetime

    all_rows = sheetdata.find_rows(_S.member, matcher=None)

    results = []

    for row in all_rows:
        renewed_date = row.dict.get(_S.member.fields.renewed.name)

        # Use Joined date if Renewed is empty
        if not renewed_date:
            renewed_date = row.dict.get(_S.member.fields.joined.name)

        # Convert date string to datetime
        if renewed_date:
            try:
                renewed_date = dateutil.parser.parse(renewed_date)
            except:
                renewed_date = None

        # If we still don't have a renewed date... the user is probably
        # very old or invalid. Set the date to a long time ago, so it gets
        # culled out.
        if not renewed_date:
            renewed_date = datetime.datetime(1970, 1, 1)

        if after_datetime and not (after_datetime <= renewed_date):
            continue

        if before_datetime and not (before_datetime >= renewed_date):
            continue

        # If we passed those two checks, then it's a hit.

        results.append(row)

    return results
Exemple #3
0
def process_mailchimp_updates():
    """Checks Members and Volunteers spreadsheets for records that need updating
    in MailChimp.
    """

    for sheet, mailchimp_upsert in (
        (_S.member, mailchimp.upsert_member_info),
        (_S.volunteer, mailchimp.upsert_volunteer_info),
    ):

        rows = sheetdata.find_rows(
            sheet, lambda d: not d[sheet.fields.mailchimp_updated.name])

        rows_to_update = []

        for row in rows:
            if not row.dict.get(sheet.fields.id.name):
                logging.error('Member or Volunteer missing ID value: %s',
                              row.dict)
                continue

            if not row.dict.get(sheet.fields.email.name):
                # If there's no email, we don't add to MailChimp
                continue

            # Set the MailChimp update datetime
            row.dict[sheet.fields.mailchimp_updated.
                     name] = utils.current_datetime()

            # Update MailChimp. Note that this involves a network call.
            # TODO: Is there a bulk upsert for Mailchimp?
            mailchimp_upsert(row.dict)

            rows_to_update.append(row)

        sheetdata.update_rows(sheet, rows_to_update)
Exemple #4
0
def get_skills_categories() -> List[str]:
    """Get a list of all skills categories from the sheet.
    """
    rows = sheetdata.find_rows(_S.skills_category, matcher=None)
    return [r.dict for r in rows]
Exemple #5
0
def get_volunteer_interests() -> List[str]:
    """Get a list of all volunteer interests from the sheet.
    """
    rows = sheetdata.find_rows(_S.volunteer_interest, matcher=None)
    return [r.dict for r in rows]