本文整理汇总了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"))