Esempio n. 1
0
def get_latest_n26(name, limit=n26_fetched_transactions):
    if name not in login_N26:
        error('#get_latest_n26 Invalid name to log in to N26 : ' + name)
        return failure_response(
            'Invalid name to log in to N26'), empty_data_dataframe()
    access_token = get_access_token_from_refresh_token(name)
    if access_token.is_invalid():
        error('#get_latest_n26 Invalid N26 token : ' + name)
        return failure_response('Invalid N26 token'), empty_data_dataframe()

    headers = {'Authorization': 'bearer ' + str(access_token.value)}
    req_transactions = requests.get(n26_url + '/api/smrt/transactions?limit=' +
                                    str(limit),
                                    headers=headers)
    data = req_transactions.json()
    return success_response(), format_n26_df(list_of_dict_to_df(data), name)
Esempio n. 2
0
class MergeDataFromSingleAccount(TestCase):
    saved_current_data = empty_data_dataframe()
    directory = './test_files/'
    effective_merged = None

    def setUp(self):
        self.saved_current_data = read_data()
        self.effective_merged = None

    def tearDown(self):
        save_data(self.saved_current_data)

    def assert_equals_df(self, expected_merged, effective_merged):
        expected_merged = expected_merged.sort_values('id').reset_index(
            drop=True)
        effective_merged = effective_merged.sort_values('id').reset_index(
            drop=True)
        pd.testing.assert_frame_equal(expected_merged,
                                      effective_merged,
                                      check_like=True,
                                      check_dtype=False)

    def test_split_AA_to_PT(self):
        directory = 'split_AA_to_PT/'

        self.given_data_file(directory)

        self.when_merge_data(directory)

        self.then_merged_data_file_is(directory)

    def test_linked_AA_to_PT(self):
        directory = 'linked_AA_to_PT/'

        self.given_data_file(directory)

        self.when_merge_data(directory)

        self.then_merged_data_file_is(directory)

    # TOOLS

    def given_data_file(self, directory_name):
        save_data(
            read_data_from_file(self.directory + directory_name + 'data.csv'))

    def when_merge_data(self, latest_directory):
        self.latest = read_data_from_file(self.directory + latest_directory +
                                          'latest.csv')
        merge_with_data(self.latest, 'acc')
        self.effective_merged = read_data()

    def then_merged_data_file_is(self, merged_directory):
        expected_merged = read_data_from_file(self.directory +
                                              merged_directory +
                                              'expected.csv')

        self.assert_equals_df(expected_merged, self.effective_merged)
Esempio n. 3
0
def lunchr_df_first_page(access_token):
    response, content = get_content_page_number(access_token)
    if not is_successful(response):
        return response, empty_data_dataframe()

    payments = content['payments_history']
    payments = remove_unprocessed_payments(payments)

    return response, layered_dict_to_df(payments)
Esempio n. 4
0
def identify_new_and_gone(data, latest_data, account):
    if df_is_not_empty(latest_data):
        add_link_ids(latest_data, '+', '-')
        condition1 = data['account'] == account
        condition2 = data['type'] != 'FIC'
        previous_data = data[both_series_are_true(condition1, condition2)]
        new_data = latest_data[latest_data['id'].isin(previous_data['id']) ==
                               False]
        previous_in_range = previous_data[
            previous_data['date'] >= min(latest_data['date'])]
        gone_data = previous_in_range[previous_in_range['id'].isin(
            latest_data['id']) == False]
        if df_is_not_empty(gone_data):
            add_link_ids(gone_data, '+', '-')
            add_column_with_value(new_data, 'replaces_a_pending', False)
            return new_data, gone_data
        return new_data, empty_data_dataframe()
    return empty_data_dataframe(), empty_data_dataframe()
Esempio n. 5
0
def get_latest_lunchr():
    access_token = get_token(login_lunchr)
    response, lunchr_df = lunchr_df_first_page(access_token)
    if not is_successful(response):
        return empty_data_dataframe()
    drop_other_columns(lunchr_df, lunchr_dictionary.keys())
    format_lunchr_df(lunchr_df)
    account = list(lunchr_df['account'])[0]

    lunchr_df = process_lunchr_cb_transaction(lunchr_df)
    real_lunchr_df = remove_already_present_id(lunchr_df, account, limit=90)

    return real_lunchr_df