예제 #1
0
import settings
from object.User import User
import json

if __name__ == '__main__':
    adminUserUsername = settings.ADMIN_USERNAME
    adminPassword = settings.ADMIN_PASSWORD

    print("login as user: "******"ok!!!")

    url = settings.API_HOST + '/obp/v3.0.0/banks'
    result = session.request('GET', url, verify=settings.VERIFY)
    banks = [bank['id'] for bank in json.loads(result.content)['banks']]

    for bank in banks:
        url = settings.API_HOST + '/obp/v3.0.0/banks/{}/firehose/accounts/views/{}'.format(
            bank, "owner")
        result = session.request('GET', url, verify=settings.VERIFY)
        if result.status_code == 200:
            accounts_list = json.loads(result.content)['accounts']
            for account in accounts_list:
                print(json.dumps(account, indent=4))
                firehose_url = settings.API_HOST + '/obp/v3.0.0/banks/{}/firehose/accounts/{}/views/{}/transactions'\
                    .format(bank,account['id'], "owner")
                firehose_result = session.request('GET',
                                                  url,
                                                  verify=settings.VERIFY)
                print("firehose transactions:")
예제 #2
0
from requests_oauthlib import OAuth1Session
import json

import settings
from object.PostCounterparty import PostCounterparty
from object.User import User

if __name__ == "__main__":
    json_object_counterparty = PostCounterparty.load(
        settings.FILE_ROOT + "OBP_sandbox_counterparties_pretty_2.json")

    counterparty_list = [
        val for sublist in json_object_counterparty for val in sublist
    ]

    json_object_user = User.load(settings.FILE_ROOT +
                                 "OBP_sandbox_pretty_2.json")

    for user_dict in json_object_user['users']:
        user = User(user_dict['user_name'], user_dict['password'],
                    user_dict['email'])
        print("login as user: "******"get users private accounts")
        private_account = user.get_user_private_account()
        account_list = json.loads(private_account)['accounts']
        print("ok!!!")

        print("get other accounts for the accounts")
        for account in account_list:
            bank_id = account['bank_id']
            region = bank_id.split('.')[2]
예제 #3
0
import settings

from object.Account import Account
from object.Bank import Bank
from object.Branch import Branch, ATM
from object.Counterparty import Counterparty
from object.Customer import Customer
from object.Product import Product
from object.Routing import top_merchants
from object.Transaction import Transaction
from object.User import User, mails

if __name__ == '__main__':
    user_number = 10
    user_list = []
    userGenerator = User.Generator(user_number)
    for i in range(user_number):
        user_list.append(next(userGenerator))

    bank_number = 3
    bank_list = []

    branch_list = []
    branch_number = 4
    atm_list = []
    atm_number = 6
    product_list = []
    product_number = 10
    bankGenerator = Bank.Generator(bank_number)
    for i in range(bank_number):
        bank = next(bankGenerator)
예제 #4
0
def get_user_from_id(users, id):
    if users.get(id) is not None: return users[id]
    return User(id, [])
예제 #5
0
def generate_main_file():
    user_list = User.generator_for_file(settings.OPTIONS_PATH)
    bank_number = settings.BANK_NUMBER

    branch_list = []
    branch_number = settings.BRANCH_NUMBER
    atm_list = []
    atm_number = settings.ATM_NUMBER
    product_list = []
    product_number = settings.PRODUCT_NUMBER
    bank_list = Bank.generate_from_file(bank_number)
    for bank in bank_list:
        branch_list.extend(Branch.generate_from_file(bank, branch_number))
        atm_list.extend(ATM.generate_from_file(bank, atm_number))
        product_list.extend(Product.generate_from_file(bank, product_number))

    account_list = []
    for user in user_list:
        branch_tmp = random.choice(branch_list)
        account1 = user.create_account(branch_tmp, "CURRENT", user.country,
                                       user.current)
        account1.set_behavior(
            income=user.current,
            spending_frequency={
                "food": user.food,
                "utility": user.utility,
                "clothing": user.clothing,
                "auto": user.auto,
                "health": user.health,
                "entertainment": user.entertainment,
                "gift": user.gift,
                "education": user.education,
                "fee": user.fee
            },
            housing_type={"RENT": -user.rent} if user.rent > 0 else None)
        account_list.append(account1)

        branch_tmp = random.choice(branch_list)
        account2 = user.create_account(branch_tmp, "SAVING", user.country,
                                       user.savings)
        account2.set_behavior(income=user.savings)
        account_list.append(account2)

    months = 36
    date_start = date.today() - timedelta(days=months * 30)
    transaction_list = []
    for i in range(months):
        date_start = date_start + timedelta(days=30)
        for account in account_list:
            transaction_list.extend(account.generateTransaction(date_start))

    with open("transaction.csv", 'w') as csv_file:
        fnames = [
            'id', 'bank', 'counterparty', 'posted', 'new_balance', 'value',
            'type', 'user', 'account_type'
        ]
        # wr = csv.DictWriter(csv_file, fieldnames=fnames, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
        # wr.writeheader()
        wr = csv.writer(csv_file, delimiter=',')
        wr.writerow(fnames)
        for transaction in transaction_list:
            wr.writerow([
                transaction.id, transaction.this_account.branch.bank.id,
                transaction.other_counterparty,
                str(transaction.posted), transaction.new_balance,
                '{:.2f}'.format(transaction.value), transaction.type,
                transaction.this_account.user[0].username,
                transaction.this_account.type
            ])

    output_dir = settings.OUTPUT_PATH
    try:
        os.makedirs(output_dir)
    except:
        pass
    with open('{}sandbox_pretty.json'.format(output_dir), 'w') as outfile:
        json.dump(
            {
                "users": user_list,
                "banks": bank_list,
                "branches": branch_list,
                "accounts": account_list,
                "atms": atm_list,
                # "counterparties":counterparty_list,
                "products": product_list,
                "transactions": transaction_list
            },
            outfile,
            default=lambda x: x.dict(),
            indent=4)

    customer_list = []
    for user in user_list:
        for bank in bank_list:
            customer_list.append(user.create_customer(bank))

    with open('{}customers_pretty.json'.format(output_dir), 'w') as outfile:
        json.dump(customer_list, outfile, default=lambda x: x.dict(), indent=4)
import csv
import json
import os
import random
from datetime import timedelta, date

import settings
from object.Bank import Bank
from object.Branch import Branch, ATM
from object.Product import Product
from object.User import User

if __name__ == '__main__':
    user1 = next(User.Generator(1, 'male', 'Married', 'Retired', 'BA.'))
    user2 = next(User.Generator(1, 'female', 'Engaged', 'Employed', 'BA.'))

    user_list = [user1, user2]
    bank_number = 3
    bank_list = []

    branch_list = []
    branch_number = 4
    atm_list = []
    atm_number = 6
    product_list = []
    product_number = 10
    bankGenerator = Bank.Generator(bank_number)
    for i in range(bank_number):
        bank = next(bankGenerator)
        bank_list.append(bank)
        branchGenerator = Branch.Generator(bank, branch_number)
    print("Got {} records".format(len(json_customers)))

    customer_list = [
        PostCustomer(customer['customer_number'], customer['legal_name'],
                     customer['mobile_phone_number'], customer['email'],
                     customer['face_image'], customer['date_of_birth'],
                     customer['relationship_status'], customer['dependants'],
                     customer['dob_of_dependants'],
                     customer['highest_education_attained'],
                     customer['employment_status'], customer['kyc_status'],
                     customer['last_ok_date'], customer['bank_id'],
                     customer['credit_rating'], customer['credit_limit'])
        for customer in json_customers
    ]

    json_user = User.load(settings.FILE_ROOT + "OBP_sandbox_pretty.json")
    print("Got {} users".format(len(json_user['users'])))

    print("login as user: "******"ok!!!")

    print("Got {} banks".format(len(json_user['banks'])))
    bank_list = []
    for bank in json_user['banks']:
        bank_list.append(
            Bank(bank['id'], bank['short_name'], bank['full_name'],
                 bank['logo'], bank['website']))

    for user_dict in json_user['users']:
예제 #8
0
        return False
    elif 'scope' in role.lower():
        return False
    elif 'entitlement' in role.lower():
        return False
    else:
        return True


if __name__ == "__main__":

    adminUserUsername = settings.ADMIN_USERNAME
    adminPassword = settings.ADMIN_PASSWORD

    print("login as administrator: ")
    admin_user = User(adminUserUsername, adminPassword)
    session = admin_user.direct_login()
    print("ok!!!")

    json_object_user = User.load(settings.FILE_ROOT + "users.json")
    url = settings.API_HOST + '/obp/v3.0.0/banks'
    result = session.request('GET', url, verify=settings.VERIFY)
    banks = [bank['id'] for bank in json.loads(result.content)['banks']]

    url = settings.API_HOST + '/obp/v3.1.0/roles'
    result = session.request('GET', url, verify=settings.VERIFY)
    roles = json.loads(result.content)['roles']

    if 'users' in json_object_user:
        users = json_object_user['users']
        for user in users: