def _load_accounts(accounts_path: str, logger: logging.Logger) -> List[Account]:
    try:
        with open(accounts_path, 'r') as file_obj:
            reader = csv.DictReader(file_obj)
            return [Account(**row_data) for row_data in reader]

    except OSError:
        return None
def record_date_scraped(
    all_accounts: Iterable[Account], scraped_account: Account
) -> Iterator[Account]:

    for account in all_accounts:
        if account.identifier == scraped_account.identifier:
            account_data = asdict(account)
            account_data['date_scraped'] = datetime.utcnow()
            yield Account(**account_data)
        else:
            yield account
Ejemplo n.º 3
0
def accounts_with_centrality(
        graph: nx.DiGraph,
        centrality_algorithm: str) -> Generator[Account, None, None]:
    centrality_function = CENTRALITY_METRIC_FUNCTIONS[centrality_algorithm]

    data_by_id = _combine(centrality=centrality_function(graph),
                          username=nx.get_node_attributes(graph, 'username'),
                          full_name=nx.get_node_attributes(graph, 'fullName'))
    for identifier, data in data_by_id.items():
        try:
            yield Account(identifier=identifier, **data)
        except TypeError:
            raise TypeError(f"Unabled to instantiate Account object "
                            f"with id {identifier} using data: {data}.")
def _centrality_from_new(old: Iterable[Account],
                         new: Iterable[Account]) -> Iterator[Account]:
    old_accounts_map = {account.identifier: account for account in old}
    new_accounts_map = {account.identifier: account for account in new}

    for identifier, old_account in old_accounts_map.items():
        new_account = new_accounts_map.get(identifier)

        if new_account:
            account_data = asdict(old_account)
            account_data['centrality'] = new_account.centrality
            yield Account(**account_data)

        else:
            yield old_account
Ejemplo n.º 5
0
def account_two(account_two_data):
    return Account(**account_two_data)
Ejemplo n.º 6
0
def account_one(account_one_data):
    return Account(**account_one_data)
def account_two_max_centrality(account_two_data_max_centrality):
    return Account(**account_two_data_max_centrality)
def account_two_with_date_scraped(account_two_data_with_date_scraped):
    return Account(**account_two_data_with_date_scraped)
def account_one_with_date_scraped(account_one_data_with_date_scraped):
    return Account(**account_one_data_with_date_scraped)
def account_one_max_centrality(account_one_data_max_centrality):
    return Account(**account_one_data_max_centrality)
def account_six(account_six_data):
    return Account(**account_six_data)
def account_five(account_five_data):
    return Account(**account_five_data)
def account_four(account_four_data):
    return Account(**account_four_data)
def account_three(account_three_data):
    return Account(**account_three_data)