-
Notifications
You must be signed in to change notification settings - Fork 3
/
utils.py
37 lines (31 loc) · 1.36 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import re
from config import CONFIG
ORGS_NAME_MAPPING = CONFIG['org_names_mapping'].get()
def group_projects_by_owner(projects):
projects_by_owner = dict(NO_OWNER=[])
for project in projects:
owners = project.get('owners_id')
for owner in owners:
prjs = projects_by_owner.setdefault(owner, [])
prjs.append(project)
if not owners:
projects_by_owner['NO_OWNER'].append(project)
return projects_by_owner
def extract_username(member):
username = re.search('(.*)@.*', member).group(1)
return username
def print_info(projects):
print('#{} projects.'.format(len(projects)))
for project in projects:
project_id = project.get('projectId')
org = ORGS_NAME_MAPPING.get(project.get('parent').get('id'))
created_days_ago = int(project.get('createdDaysAgo', '-1'))
cost_value = project.get('costSincePreviousMonth', 'Unknown')
cost_currency = project.get('costCurrency', 'Unknown')
owners = project.get('owners', 'Unknown')
owners_id = project.get('owners_id', 'Unknown')
created_time = project.get('createTime', 'Unknown')
print('{}/{}, CreatedTime={}, Age={}d, Cost={} {}, Owners={}, '
'Users={}.'.format(
org, project_id, created_time, created_days_ago, cost_value,
cost_currency, owners, owners_id))