예제 #1
0
def get_user_details_data(username: str,
                          lang: str) -> Optional[List[Dict[str, str]]]:
    html = http_get(f'{URL}/{username}?inc=score&lang={lang}')
    if html is None:
        log.warning(f'could_not_get_user_details', username=username)
        return

    pseudo = extract_pseudo(html)
    score = extract_score(html)
    avatar_url = extract_avatar_url(html)
    if score == 0:  # Manage case when score is null (score is not displayed on profile)
        log.warning(f'could_not_get_user_details', username=username)
        return

    nb_challenges_solved, nb_challenges_tot = extract_nb_challenges_solved(
        html)
    ranking, ranking_tot = extract_ranking(html)
    ranking_category = extract_ranking_category(html)
    categories = extract_challenges(html)
    return [{
        'pseudo': pseudo,
        'score': score,
        'avatar_url': avatar_url,
        'nb_challenges_solved': nb_challenges_solved,
        'nb_challenges_tot': nb_challenges_tot,
        'ranking': ranking,
        'ranking_tot': ranking_tot,
        'ranking_category': ranking_category,
        'categories': categories,
    }]
예제 #2
0
def get_user_contributions_data(
    username: str, lang: str
) -> Tuple[contribution_type, contribution_type, all_contributions_type]:
    html = http_get(f'{URL}/{username}?inc=contributions&lang={lang}')
    if html is None:
        log.warning('could_not_get_user_contributions', username=username)
        return None, None, None

    nb_challenges_pages, nb_solutions_pages = extract_contributions_page_numbers(
        html)
    if nb_challenges_pages == 0 and nb_solutions_pages == 0:
        return None, None, None  # no challenges or solutions published by this user

    challenges_contributions = format_contributions_challenges(
        username, lang, nb_challenges_pages)
    solutions_contributions = format_contributions_solutions(
        username, lang, nb_solutions_pages)

    all_contributions = [{
        'contributions': {
            'challenges': challenges_contributions,
            'solutions': solutions_contributions
        }
    }]

    return challenges_contributions, solutions_contributions, all_contributions
예제 #3
0
def get_user_ctf_data(username: str,
                      lang: str) -> Optional[List[Dict[str, str]]]:
    html = http_get(f'{URL}/{username}?inc=ctf&lang={lang}')
    if html is None:
        log.warning(f'ctf_page_not_found', username=username)
        return

    if is_not_participating(html):
        log.warning(f'{username} never played CTF all the day.')
        return

    pseudo = extract_pseudo(html)
    num_success, num_try, description = extract_summary(html)
    tp_function = partial(get_ctf_page, username)
    nb_ctf_pages = 2  # might need to be changed in some months/years
    tp_argument = list(range(nb_ctf_pages))
    with ThreadPool(nb_ctf_pages) as tp:
        response_ctf = tp.map(tp_function, tp_argument)
    ctfs = list(
        itertools.chain(response_ctf))  # concatenate all solutions lists

    return [{
        'pseudo': pseudo,
        'num_success': num_success,
        'num_try': num_try,
        'description': description,
        'ctfs': ctfs,
    }]
예제 #4
0
def get_solution_contributions(
        username: str, lang: str,
        page_index: int) -> Optional[List[Dict[str, str]]]:
    url = f'{URL}/{username}?inc=contributions&lang={lang}&debut_solutions_auteur={5 * page_index}#pagination_solutions_auteur'
    html = http_get(url)
    if html is None:
        log.warning(f'could_not_get_solution_contributions',
                    username=username,
                    page_index=page_index)
        return
    return extract_solutions_contributions(html)
예제 #5
0
def get_ctf_page(username: str,
                 page_index: int) -> Optional[List[Dict[str, str]]]:
    url = f'{URL}/{username}?inc=ctf&debut_ctf_alltheday_vm_dispo={50 * page_index}#pagination_ctf_alltheday_vm_dispo'
    html = http_get(url)
    if html is None:
        log.warning(f'ctf_page_not_found',
                    username=username,
                    page_index=page_index)
        return

    return extract_ctf(html)
예제 #6
0
def get_user_stats_data(username: str, lang: str) -> Optional[Dict[str, str]]:
    html = http_get(f'{URL}/{username}?inc=statistiques&lang={lang}')
    if html is None:
        log.warning(f'could_not_get_user_stats', username=username)
        return

    pseudo = extract_pseudo(html)
    solved_challenges = extract_stats(html)

    return {
        'pseudo': pseudo,
        'solved_challenges': solved_challenges,
    }
예제 #7
0
def get_user_profile_data(username: str,
                          lang: str) -> Optional[List[Dict[str, str]]]:
    html = http_get(f'{URL}/{username}?lang={lang}')
    if html is None:
        log.warning(f'user_profile_not_found', username=username)
        return

    pseudo = extract_pseudo(html)
    score = extract_score(html)
    avatar_url = extract_avatar_url(html)
    response = [{
        'pseudo': pseudo,
        'score': score,
        'avatar_url': avatar_url,
    }]
    return response