Example #1
0
def get_trello_board_cards_data(board_id, members_names, my_team, labels,
                                filter_type, list_names, personal_key,
                                personal_token):
    """Get all relevant data from trello board cards

    Parameters:
        board_id (string): The id of a board as trello saving it.
        members_names (dict): All the members names of the board,
                              member id as a key and member name as a value. F.e. {'TxCogm4e0rI': 'Tomer'}
        my_team (array): The names of the relevant trello members to look if they assigned to card.
        labels (string): The relevant label to look for.
        filter_type (string): Can be 'Team' or 'Label', it will decide the type of flitering by.
        list_names (dict): All the list (columns) of the board,
                           column id as a key and column name as a value. F.e. {'To19302Do': 'To Do'}
        personal_key (string): Personal developer API key of trello user.
        personal_token (string): Generated Token of trello user.

    Returns:
        sorted_array_of_parsed_cards (array): Return array of meaningful data of cards:
                                              members, name, url, column.
                                              sorted by column value
        Or raising an error if http is failing
    """
    array_of_parsed_cards = list()
    trello_url = 'https://api.trello.com/1/boards/' + board_id + '/cards?key=' + personal_key + '&token=' + personal_token
    response = simple_get(trello_url)
    # make it valid JSON
    trello_cards_as_json = json.loads(response)
    for trello_card in trello_cards_as_json:
        parsed_card = {}
        parsed_card['members'] = list()
        parsed_card['labels'] = list()
        is_team_card = False
        is_label_card = False
        for members_id in trello_card['idMembers']:
            if members_names[members_id] in my_team:
                is_team_card = True
                parsed_card['members'].append(members_names[members_id])
        for label in trello_card['labels']:
            parsed_card['labels'].append(label['name'])
            if label['name'] in labels:
                is_label_card = True
        if (not is_team_card
                and filter_type == 'team') or (not is_label_card
                                               and filter_type == 'label'):
            continue
        parsed_card['column'] = list_names[trello_card['idList']]
        parsed_card['name'] = trello_card['name']
        parsed_card['url'] = trello_card['url']
        array_of_parsed_cards.append(parsed_card)
    sorted_array_of_parsed_cards = sorted(array_of_parsed_cards,
                                          key=lambda k: k['column'])
    return sorted_array_of_parsed_cards

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(trello_url))
Example #2
0
def get_my_repos(personal_token):
    """Get all repos of user

    Parameters:
        personal_token (string): access token from github

    Returns:
        github_repos_as_json (dict): dictionary of 100 recent repos in github of the user
        Or raising an error if http is failing

    """
    github_url = GITHUB_V3_URL + '/user/repos?per_page=100'
    response = simple_get(github_url, personal_token)
    github_repos_as_json = json.loads(response)
    return github_repos_as_json

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(github_url))
Example #3
0
def get_files_change_of_a_pr(repo_name, pr, personal_token):
    """Get all files change of specific pull request

    Parameters:
        repo_name (string): name of the relevant repository
        personal_token (string): access token from github

    Returns:
        github_files_as_json (dict): dictionary of 100 recent pull requests of specific repository
        Or raising an error if http is failing

    """

    github_url = GITHUB_V3_URL + '/repos/' + repo_name + '/pulls/' + str(
        pr['number']) + '/files?access_token=' + personal_token
    response = simple_get(github_url, personal_token)
    github_files_as_json = json.loads(response)
    return github_files_as_json
Example #4
0
def get_approved_prs_of_a_repo(repo_name, personal_token):
    """

    Parameters:
        repo_name (string): The repository name of the pull requests
        personal_token (string): access token from github

    Returns:
        approved_prs_of_a_repo_as_json (dict): dictionary of all approved pull requests
        Or raising an error if http is failing

    """
    github_url = GITHUB_V3_URL + '/search/issues?q=is:open+is:pr+review:approved+repo:' + repo_name
    response = simple_get(github_url, personal_token)
    approved_prs_of_a_repo_as_json = json.loads(response) if response else []
    return approved_prs_of_a_repo_as_json

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(github_url))
Example #5
0
def get_statuses_of_a_pull(statuses_url, personal_token):
    """Get all checks statuses of a pull request

    Parameters:
        statuses_url (string): Github url for checks statuses of a pull
        personal_token (string): access token from github

    Returns:
        statuses_of_a_pull_as_json (dict): dictionary of all checks statuses of a pull request
        Or raising an error if http is failing

    """
    github_url = statuses_url
    response = simple_get(github_url, personal_token)
    statuses_of_a_pull_as_json = json.loads(response)
    return statuses_of_a_pull_as_json

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(github_url))
Example #6
0
def get_pulls_of_a_repo(repo_name, personal_token):
    """Get all pulls of specific repository

    Parameters:
        repo_name (string): name of the relevant repository
        personal_token (string): access token from github

    Returns:
        github_pulls_as_json (dict): dictionary of 100 recent pull requests of specific repository
        Or raising an error if http is failing

    """
    github_url = GITHUB_V3_URL + '/repos/' + repo_name + '/pulls?per_page=100&direction=desc'
    response = simple_get(github_url, personal_token)
    github_pulls_as_json = json.loads(response)
    return github_pulls_as_json

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(github_url))
Example #7
0
def get_trello_board_data(board_id, personal_key, personal_token):
    """Get all data for one trello board of user

    Parameters:
        board_id (string): The id of a board as trello saving it.
        personal_key (string): Personal developer API key of trello user.
        personal_token (string): Generated Token of trello user.

    Returns:
        trello_board_as_json (json): Return the id and the name of the trello board in a json
        Or raising an error if http is failing

    """
    trello_url = 'https://api.trello.com/1/boards/' + board_id + '?fields=name,url&key=' + personal_key + '&token=' + personal_token
    response = simple_get(trello_url)
    trello_board_as_json = json.loads(response)
    return trello_board_as_json

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(trello_url))
Example #8
0
def get_ynet_data():
    """
    Parse the page where the data of ynet news and take the main headers
    """
    ynet_url = 'https://ynet.co.il/home/0,7340,L-8,00.html'
    response = simple_get(ynet_url)

    if response is not None:
        soup = BeautifulSoup(response, 'html.parser')
        titles = []
        titles_squares = soup.find_all("div", class_="str3s_txt")
        for ts in titles_squares:
            titles.append({
                'title': ts.find("div", class_="title").text,
                'sub_title': ts.find("div", class_="sub_title").text
            })
        return titles

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(ynet_url))
Example #9
0
def get_walla_data():
    """
    Parse the page where the data of walla news and take the main headers
    """
    walla_url = 'https://www.walla.co.il/'
    response = simple_get(walla_url)

    if response is not None:
        soup = BeautifulSoup(response, 'html.parser')
        titles = []
        titles_squares = [data.find_all("article",  {"class": ["article", "fc", "common-article"]}) for data in soup.find_all("section", class_="editor-selections")]
        for ts in titles_squares[0]:
            titles.append({
                'title': ts.find("span", class_="text").text,
                'sub_title': ts.find("p").text
            })
        return titles

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(walla_url))
Example #10
0
def get_trello_boards(personal_key, personal_token):
    """Get all trello boards of user

    Parameters:
        personal_key (string): Personal developer API key of trello user.
        personal_token (string): Generated Token of trello user.

    Returns:
        boards (dict): trello boards of user, board id as a key and board name as a value.
                       F.E. {'ytNr5B5o9': 'New Board'}
        Or raising an error if http is failing

    """
    trello_url = 'https://api.trello.com/1/members/me/boards?key=' + personal_key + '&token=' + personal_token
    response = simple_get(trello_url)
    trello_boards_as_json = json.loads(response)
    boards = dict()
    for trello_card in trello_boards_as_json:
        boards[trello_card['shortLink']] = trello_card['name']
    return boards

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(trello_url))
Example #11
0
def get_trello_board_lists_data(board_id, personal_key, personal_token):
    """Get all lists of one trello board

    Parameters:
        board_id (string): The id of a board as trello saving it.
        personal_key (string): Personal developer API key of trello user.
        personal_token (string): Generated Token of trello user.

    Returns:
        list_names (dict): Return dictionary of columns.
                           Column id as a key and column name as a value. F.e. {'To19302Do': 'To Do'}
        Or raising an error if http is failing
    """
    list_names = {}
    trello_url = 'https://api.trello.com/1/boards/' + board_id + '/lists?key=' + personal_key + '&token=' + personal_token
    response = simple_get(trello_url)
     # make it valid JSON
    trello_lists_as_json = json.loads(response)
    for trello_list in trello_lists_as_json:
        list_names[trello_list['id']] = trello_list['name']
    return list_names

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(trello_url))
Example #12
0
def get_trello_board_members_data(board_id, personal_key, personal_token):
    """Get all members of one trello board

    Parameters:
        board_id (string): The id of a board as trello saving it.
        personal_key (string): Personal developer API key of trello user.
        personal_token (string): Generated Token of trello user.

    Returns:
        members_names (dict): Return dictionary of members.
                           Member id as a key and member name as a value. F.e. {'TxCogm4e0rI': 'Tomer'}
        Or raising an error if http is failing
    """
    members_names = {}
    trello_url = 'https://api.trello.com/1/boards/' + board_id + '/members?key=' + personal_key + '&token=' + personal_token
    response = simple_get(trello_url)
     # make it valid JSON
    trello_members_as_json = json.loads(response)
    for trello_member in trello_members_as_json:
        members_names[trello_member['id']] = trello_member['fullName']
    return members_names

    # Raise an exception if we failed to get any data from the url
    raise Exception('Error retrieving contents at {}'.format(trello_url))