def request_user_email(user_id, github_api_auth): """ Get email from the profile """ rsp = requests.get( EndPoint.add_auth_info(EndPoint.user_profile(user_id), github_api_auth)) # raise error when found nothing rsp.raise_for_status() rsp = rsp.json() ge = GithubUserEmail() ge.g_id = rsp['login'] ge.name = rsp['name'].strip() if rsp['name'] else rsp['login'] ge.email = rsp['email'] ge.from_profile = True # Get user email from events if ge.email is None: rsp = requests.get( EndPoint.add_auth_info(EndPoint.user_events(user_id), github_api_auth)) # raise error when found nothing rsp.raise_for_status() email = get_email_from_events(rsp, ge.name) if email is not None: ge.email = email ge.from_profile = False return ge
def request_user_email(user_id, github_api_auth): """ Get email from the profile """ rsp = requests.get(EndPoint.add_auth_info(EndPoint.user_profile(user_id), github_api_auth)) # raise error when found nothing rsp.raise_for_status() rsp = rsp.json() ge = GithubUserEmail() ge.g_id = rsp['login'] ge.name = rsp['name'].strip() if rsp['name'] else rsp['login'] ge.email = rsp['email'] ge.from_profile = True # Get user email from events if ge.email is None: rsp = requests.get(EndPoint.add_auth_info(EndPoint.user_events(user_id), github_api_auth)) # raise error when found nothing rsp.raise_for_status() email = get_email_from_events(rsp, ge.name) if email is not None: ge.email = email ge.from_profile = False return ge
def repository(user_id, repo, github_api_auth): rsp = requests.get(EndPoint.add_auth_info(EndPoint.repository(user_id, repo), github_api_auth)) rsp = rsp.json() repo = GithubRepository() repo.repo_id = rsp['id'] repo.name = rsp['name'] repo.description = rsp['description'] repo.stargazers_count = rsp['stargazers_count'] repo.watchers_count = rsp['watchers_count'] repo.forks_count = rsp['forks_count'] return repo
def api_status(github_api_auth): rsp = requests.get(EndPoint.add_auth_info(EndPoint.rate_limit(), github_api_auth)) rsp = rsp.json() status = GithubAPIStatus() status.core_reset_time = rsp['resources']['core']['reset'] status.core_limit = rsp['resources']['core']['limit'] status.core_remaining = rsp['resources']['core']['remaining'] status.search_reset_time = rsp['resources']['search']['reset'] status.search_limit = rsp['resources']['search']['limit'] status.search_remaining = rsp['resources']['search']['remaining'] return status
def api_status(github_api_auth): rsp = requests.get( EndPoint.add_auth_info(EndPoint.rate_limit(), github_api_auth)) rsp = rsp.json() status = GithubAPIStatus() status.core_reset_time = rsp['resources']['core']['reset'] status.core_limit = rsp['resources']['core']['limit'] status.core_remaining = rsp['resources']['core']['remaining'] status.search_reset_time = rsp['resources']['search']['reset'] status.search_limit = rsp['resources']['search']['limit'] status.search_remaining = rsp['resources']['search']['remaining'] return status
def repository(user_id, repo, github_api_auth): rsp = requests.get( EndPoint.add_auth_info(EndPoint.repository(user_id, repo), github_api_auth)) rsp = rsp.json() repo = GithubRepository() repo.repo_id = rsp['id'] repo.name = rsp['name'] repo.description = rsp['description'] repo.stargazers_count = rsp['stargazers_count'] repo.watchers_count = rsp['watchers_count'] repo.forks_count = rsp['forks_count'] return repo
def request_user_email(user_id, github_api_auth): """ Get email from the profile """ rsp = requests.get(EndPoint.add_auth_info(EndPoint.user_profile(user_id), github_api_auth)) # raise error when found nothing rsp.raise_for_status() rsp = rsp.json() ge = GithubUserEmail() ge.g_id = rsp['login'] ge.name = rsp['name'] if rsp['name'] else rsp['login'] ge.email = rsp['email'] # TODO user email from events return ge
def request_user_email(user_id, github_api_auth): """ Get email from the profile """ rsp = requests.get( EndPoint.add_auth_info(EndPoint.user_profile(user_id), github_api_auth)) # raise error when found nothing rsp.raise_for_status() rsp = rsp.json() ge = GithubUserEmail() ge.g_id = rsp['login'] ge.name = rsp['name'] if rsp['name'] else rsp['login'] ge.email = rsp['email'] # TODO user email from events return ge
def request_user_ids_by_roll_pages(url, total_pages, per_page): # loop page with url user_ids = [] for i in range(0, total_pages + 1): url = EndPoint.pagination(url, page=(i + 1), per_page=per_page) r = requests.get(url) # raise error when found nothing r.raise_for_status() # handling result user_ids = user_ids + [info['login'] if 'login' in info else info['owner']['login'] for info in r.json()] return user_ids
def integrate_user_ids(user_id, repo, actions, github_api_auth): user_ids = [] for action_type in actions: # get repo github_repo = repository(user_id, repo, github_api_auth) # pagination per_page = 100 total_pages = select_action_count(github_repo, action_type) / per_page # create url url = EndPoint.add_auth_info(select_end_porint_builder(action_type)(user_id, repo), github_api_auth) # get id by rolling pages user_ids = user_ids + request_user_ids_by_roll_pages(url, total_pages, per_page) return OrderedDict.fromkeys(user_ids).keys()
def request_user_ids_by_roll_pages(url, total_pages, per_page): # loop page with url user_ids = [] for i in range(0, total_pages + 1): url = EndPoint.pagination(url, page=(i + 1), per_page=per_page) r = requests.get(url) # raise error when found nothing r.raise_for_status() # handling result user_ids = user_ids + [ info['login'] if 'login' in info else info['owner']['login'] for info in r.json() ] return user_ids
def integrate_user_ids(user_id, repo, actions, github_api_auth): user_ids = [] for action_type in actions: # get repo github_repo = repository(user_id, repo, github_api_auth) # pagination per_page = 100 total_pages = select_action_count(github_repo, action_type) / per_page # create url url = EndPoint.add_auth_info( select_end_porint_builder(action_type)(user_id, repo), github_api_auth) # get id by rolling pages user_ids = user_ids + request_user_ids_by_roll_pages( url, total_pages, per_page) return OrderedDict.fromkeys(user_ids).keys()