当前位置: 首页>>代码示例>>Python>>正文


Python Group.find_sections_by_name方法代码示例

本文整理汇总了Python中group.Group.find_sections_by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Group.find_sections_by_name方法的具体用法?Python Group.find_sections_by_name怎么用?Python Group.find_sections_by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在group.Group的用法示例。


在下文中一共展示了Group.find_sections_by_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: census_leavers

# 需要导入模块: from group import Group [as 别名]
# 或者: from group.Group import find_sections_by_name [as 别名]
def census_leavers(osm, auth, term=None, csv=False,
                   no_headers=False):
    # Nasty hack - but I need a list of terms.
    somers_terms = Group(osm, auth, MAPPING.keys(), None)._sections.sections['20706'].get_terms()

    def find_term(name):
        return [_ for _ in somers_terms if _['name'] == name][0]

    terms = [find_term(_) for _ in
             ['Summer 2014',
              'Autumn 2014',
              'Spring 2015',
              'Summer 2015',
              'Autumn 2015',
              'Spring 2016',
              'Summer 2016',
              'Autumn 2016',
              'Spring 2017',
              'Summer 2017',
              'Autumn 2017',
              ]]

    pairs = [(terms[x], terms[x + 1]) for x in range(len(terms) - 1)]

    section_map = {'Garrick': 'Beavers',
                   'Paget': 'Beavers',
                   'Swinfen': 'Beavers',
                   'Maclean': 'Cubs',
                   'Somers': 'Cubs',
                   'Rowallan': 'Cubs',
                   'Erasmus': 'Scouts',
                   'Boswell': 'Scouts',
                   'Johnson': 'Scouts'}

    rows = []
    for old, new in pairs:
        old_term = Group(osm, auth, MAPPING.keys(), old['name'])
        new_term = Group(osm, auth, MAPPING.keys(), new['name'])

        old_members_raw = old_term.all_yp_members_without_senior_duplicates()
        new_members_raw = new_term.all_yp_members_without_senior_duplicates()

        old_members = [(_['first_name'], _['last_name'])
                       for _ in old_members_raw]

        new_members = [(_['first_name'], _['last_name'])
                       for _ in new_members_raw]

        missing = [_ for _ in old_members if not new_members.count(_)]

        for first, last in missing:
            sections = old_term.find_sections_by_name(first, last)
            member = old_members_raw[old_members.index((first, last))]
            age = member.age(ref_date=old.enddate).days // 365
            rows.append([old['name'], section_map[sections[0]], sections[0], first, last, age, member['date_of_birth'],
                         member['floating.gender'].lower()])

    headers = ["Last Term", "Section", "Section Name", "First", "Last", "Age", "DOB", "Gender"]

    if csv:
        w = csv_writer(sys.stdout)
        if not no_headers:
            w.writerow(list(headers))
        w.writerows(rows)
    else:
        if not no_headers:
            print(tabulate.tabulate(rows, headers=headers))
        else:
            print(tabulate.tabulate(rows, tablefmt="plain"))
开发者ID:hippysurfer,项目名称:scout-records,代码行数:71,代码来源:cli.py


注:本文中的group.Group.find_sections_by_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。