# Path: cryptofolio/api/BalanceFromAddress.py
# class BalanceFromAddress:
#     def __init__(self):
#         self.logger = Logger(__name__)
#         self.handlers = {
#             'BTC': Blockchain(),
#             'ETH': Etherscan(),
#             'LTC': Chainz(),
#             'BCH': Blockchair(),
#             'XRP': Ripple()
#         }
# 
#     def getSingleBalance(self, currency, address):
#         if currency in self.handlers:
#             return self.handlers[currency].getBalance(address)
#         return 0.0
# 
#     def getBalances(self, address_inputs):
#         result = {}
#         for i, a in enumerate(address_inputs):
#             result[a.address] = self.getSingleBalance(a.currency, a.address)
#             # poor man rate limiter
#             if (i + 1) % 5 == 0:
#                 sleep(1)
#         return result
# 
#     def getSupportedCurrencies():
#         supported_currencies = ['BTC', 'ETH', 'LTC', 'BCH', 'XRP']
#         return zip(supported_currencies, supported_currencies)


from django.conf import settings as django_settings
from django.contrib import messages
from django.contrib.auth import (
    REDIRECT_FIELD_NAME,
    login as auth_login,
    authenticate,
    update_session_auth_hash)
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import PasswordChangeForm, AuthenticationForm
from django.contrib.auth.models import User
from django.contrib.sites.shortcuts import get_current_site
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse_lazy
from django.db import transaction
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
from django.shortcuts import render, redirect, get_object_or_404, resolve_url
from django.template import RequestContext
from django.utils.http import is_safe_url
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
from . import forms
from . import models
from .api.BalanceFromAddress import BalanceFromAddress
import time
import datetime
import itertools
    balances = []

    if request.method == 'POST':
        form = forms.ManualInputForm(request.POST, instance=manual_input)
        if form.is_valid():
            form.save()
            messages.success(request, 'Balance added successfully!')
            return redirect('manual_input')
        else:
            messages.warning(request, 'There was an error adding balance!')
    else:
        form = forms.ManualInputForm(instance=manual_input)
        balances = models.ManualInput.objects.filter(user=request.user)

    context = {
        'form': form,
        'balances': balances
    }
    return render(request, 'manual.html', context)


@login_required
def remove_manual_input(request, manual_input_id):
    try:
        manual_input = models.ManualInput.objects.filter(
            user=request.user,
            id=manual_input_id
        )

        manual_input.delete()

# Path: cryptofolio/api/BalanceFromAddress.py
# class BalanceFromAddress:
#     def __init__(self):
#         self.logger = Logger(__name__)
#         self.handlers = {
#             'BTC': Blockchain(),
#             'ETH': Etherscan(),
#             'LTC': Chainz(),
#             'BCH': Blockchair(),
#             'XRP': Ripple()
#         }
# 
#     def getSingleBalance(self, currency, address):
#         if currency in self.handlers:
#             return self.handlers[currency].getBalance(address)
#         return 0.0
# 
#     def getBalances(self, address_inputs):
#         result = {}
#         for i, a in enumerate(address_inputs):
#             result[a.address] = self.getSingleBalance(a.currency, a.address)
#             # poor man rate limiter
#             if (i + 1) % 5 == 0:
#                 sleep(1)
#         return result
# 
#     def getSupportedCurrencies():
#         supported_currencies = ['BTC', 'ETH', 'LTC', 'BCH', 'XRP']
#         return zip(supported_currencies, supported_currencies)


# Path: cryptofolio/views.py
from django.conf import settings as django_settings
from django.contrib import messages
from django.contrib.auth import (
    REDIRECT_FIELD_NAME,
    login as auth_login,
    authenticate,
    update_session_auth_hash)
from django.contrib.auth.decorators import login_required
from django.contrib.auth.forms import PasswordChangeForm, AuthenticationForm
from django.contrib.auth.models import User
from django.contrib.sites.shortcuts import get_current_site
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse_lazy
from django.db import transaction
from django.http import HttpResponse, JsonResponse, HttpResponseRedirect
from django.shortcuts import render, redirect, get_object_or_404, resolve_url
from django.template import RequestContext
from django.utils.http import is_safe_url
from django.views.decorators.cache import never_cache
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
from . import forms
from . import models
from .api.BalanceFromAddress import BalanceFromAddress
import time
import datetime
import itertools

    balances = []

    if request.method == 'POST':
        form = forms.ManualInputForm(request.POST, instance=manual_input)
        if form.is_valid():
            form.save()
            messages.success(request, 'Balance added successfully!')
            return redirect('manual_input')
        else:
            messages.warning(request, 'There was an error adding balance!')
    else:
        form = forms.ManualInputForm(instance=manual_input)
        balances = models.ManualInput.objects.filter(user=request.user)

    context = {
        'form': form,
        'balances': balances
    }
    return render(request, 'manual.html', context)


@login_required
def remove_manual_input(request, manual_input_id):
    try:
        manual_input = models.ManualInput.objects.filter(
            user=request.user,
            id=manual_input_id
        )

        manual_input.delete()

        messages.success(request, 'Balance removed!')