def find_matches_gone_newsettled(new, gone, link_name, links_to_add): data = read_data() free_new = new[new['replaces_a_pending'] == False] for index_gone in gone.index.tolist(): link_value = get_loc_df(gone, index_gone, link_name) match = filter_df_one_value(free_new, link_name, link_value) if df_is_not_empty(match): index_new_settled = max(match.index) gone_transaction = gone.loc[index_gone] settled_transaction = new.loc[index_new_settled] warn('\n#merge_data ------- Identified : -------') info_df( concat_lines([ gone_transaction.to_frame().T, settled_transaction.to_frame().T ])) info('merge_data -----------------------------\n') to_relink_after_gone_replaced_with_settled(data, gone_transaction, settled_transaction, links_to_add) data = read_data() id_to_remove = gone.loc[index_gone, 'id'] recover_editable_fields(new, index_new_settled, gone, index_gone) drop_line_with_index(gone, index_gone) remove_data_on_id(id_to_remove) warn('#merge_data removing transaction' + '\n' + str(filter_df_one_value(data, 'id', id_to_remove))) assign_value_to_loc(new, index_new_settled, 'replaces_a_pending', True)
def force_refresh_bankin(): headers = get_bankin_headers_with_token() force_refresh_url = bankin_url + '/v2/items/refresh' response = requests.post(force_refresh_url, headers=headers, params=bankin_params) info('Force refresh bankin : code ' + str(response.status_code))
def get_access_token_from_refresh_token(name): refresh_token = read_refresh_token(name) if refresh_token.is_invalid(): return InvalidToken() refresh_url = n26_url + '/oauth/token' values_token = { "grant_type": "refresh_token", 'refresh_token': refresh_token.value, 'username': login_N26[name].username, 'password': login_N26[name].password } headers_token = { 'Authorization': 'Basic bXktdHJ1c3RlZC13ZHBDbGllbnQ6c2VjcmV0' } response = json.loads( requests.post(refresh_url, data=values_token, headers=headers_token).content) try: refresh_token = response['refresh_token'] access_token = response['access_token'] save_refresh_token(name, refresh_token) return Token(access_token) except KeyError: error(str(now()) + ' : Refresh token failed for ' + name) info(response) return InvalidToken()
def start_scheduler(job, seconds): _scheduler.add_job(job, trigger='interval', seconds=seconds) try: _scheduler.start() except SchedulerAlreadyRunningError: info('SchedulerAlreadyRunningError') pass
def convert_non_euro_amounts(data): if value_is_nan(total_amount(data)): info('#Recap converting currencies with current rate') exchange_rate_col = 'exchange_rate' process_currency_data(data) apply_function_to_field_overrule(data, currency_col, latest_rate_from_euro, destination=exchange_rate_col) assign_new_column( data, 'amount', get_one_field(data, amount_euro_col) / get_one_field(data, exchange_rate_col)) drop_columns(data, [exchange_rate_col]) add_column_with_value(data, currency_col, default_currency)
def authorize_mfa(mfa_token): req = urllib.request.Request(n26_url + "/api/mfa/challenge", data=json.dumps({ "challengeType": "oob", "mfaToken": mfa_token }).encode("utf-8")) req.add_header("Authorization", "Basic bXktdHJ1c3RlZC13ZHBDbGllbnQ6c2VjcmV0") req.add_header("User-Agent", USER_AGENT) req.add_header('Content-Type', 'application/json') try: url = urllib.request.urlopen(req) except urllib.error.HTTPError as e: body = json.load(e) error('Error in asking mfa challenge') info(body)
def delete_gone_from_data(gone): if df_is_not_empty(gone): warn('#merge_data NOT FOUND GONE TRANSACTIONS :') info('\n#delete_data ------- Deleting : -------') info_df(gone) info('Filtering out PT transactions') gone = filter_df_not_this_value(gone, 'type', 'PT') info('\n#delete_data ------- TO DELETE : -------') info_df(gone) info('#delete_data -----------------------------\n') data = filter_df_not_these_values(read_data(), 'id', get_one_field(gone, 'id')) save_data(data)
def createLoanOffers(self): logger.info(GR("Checking for coins to lend:---------------")) bals = self.api.returnAvailableAccountBalances() if not 'lending' in bals: return logger.info(RD("No coins found in lending account")) for coin in self.coins: if coin not in bals['lending']: logger.debug("No available %s in lending", OR(coin)) continue amount = bals['lending'][coin] logging.info("%s:%s", coin, str(amount)) if float(amount) < self.coins[coin]: logger.debug("Not enough %s:%s, below set minimum: %s", OR(coin), RD(str(amount)), BL(str(self.coins[coin]))) continue orders = self.api.returnLoanOrders(coin)['offers'] topRate = float(orders[0]['rate']) price = topRate + (self.offset * LOANTOSHI) logger.info('Creating %s %s loan offer at %s', RD(str(amount)), OR(coin), GR(str(price * 100) + '%')) logger.debug( self.api.createLoanOffer(coin, amount, price, autoRenew=0))
def to_relink_after_gone_replaced_with_settled(data, gone_transaction, settled_transaction, links_to_add): link_gone = gone_transaction['link'] id_gone = gone_transaction['id'] id_settled = settled_transaction['id'] if link_gone != default_value('link'): info('LINKED GONE TRANSACTION') all_linked = all_transactions_linked_to_this(data, id_gone) info('id gone : ' + str(id_gone)) info(all_linked) all_links = ','.join(all_linked) unlink_ids_if_possible(id_gone) links_to_add.append(all_links.replace(id_gone, id_settled))