def _get_blockchain_data(rates):
    response = requests.get("http://blockchain.info/pt/ticker")
    content = response.content
    if Rates.is_valid_blockchain_data(content):
        rates.blockchain_data = content
        rates.last_update_blockchain = timezone.now()
        rates.save()
    else:
        logger.error("got invalid Blockchain data: %s" % content)
Exemplo n.º 2
0
def _get_blockchain_data(rates):
    response = requests.get('https://blockchain.info/pt/ticker')
    content = response.content
    if Rates.is_valid_blockchain_data(content):
        rates.blockchain_data = content
        rates.last_update_blockchain = timezone.now()
        rates.save()
    else:
        logger.error('got invalid Blockchain data: %s' % content)
def _get_rates():
    q = Rates.objects.all()
    if q.count() > 0:
        rates = Rates.objects.all()[0]
        if timezone.now() - rates.last_update > timedelta(minutes=3):
            _populate_rates(rates)
    else:
        rates = Rates()
        _populate_rates(rates)
    return rates
def _get_oer_data(rates):
    response = requests.get(
        "http://openexchangerates.org/api/latest.json?app_id=%s" % settings.OPENEXCHANGERATES_API_KEY
    )
    content = response.content
    if Rates.is_valid_oer_data(content):
        rates.oer_data = content
        rates.last_update_oer = timezone.now()
        rates.save()
    else:
        logger.error("got invalid OpenExchangeRate data: %s" % content)
def _get_oer_data(rates):
    if settings.MOCK_OPENEXCHANGE_RATES:
        content = """{
          "timestamp": 1391814062,
          "base": "USD",
          "rates": {
            "BRL": 2.38329,
            "BTC": 0.0013829378,
            "USD": 1
          }
        }"""
    else:
        response = requests.get('http://openexchangerates.org/api/latest.json?app_id=%s' % settings.OPENEXCHANGERATES_API_KEY)
        content = response.content
    logger.info('got response from OpenExchangeRate: %s' % content)
    if Rates.is_valid_oer_data(content):
        rates.oer_data = content
        rates.last_update_oer = timezone.now()
        rates.save()
    else:
        logger.error('invalid OpenExchangeRate data: %s' % content)
Exemplo n.º 6
0
def _get_oer_data(rates):
    if settings.MOCK_OPENEXCHANGE_RATES:
        content = """{
          "timestamp": 1391814062,
          "base": "USD",
          "rates": {
            "BRL": 2.38329,
            "BTC": 0.0013829378,
            "USD": 1
          }
        }"""
    else:
        response = requests.get(
            'http://openexchangerates.org/api/latest.json?app_id=%s' %
            settings.OPENEXCHANGERATES_API_KEY)
        content = response.content
    logger.info('got response from OpenExchangeRate: %s' % content)
    if Rates.is_valid_oer_data(content):
        rates.oer_data = content
        rates.last_update_oer = timezone.now()
        rates.save()
    else:
        logger.error('invalid OpenExchangeRate data: %s' % content)
Exemplo n.º 7
0
    q = Rates.objects.all()
    if q.count() > 0:
        rates = Rates.objects.all()[0]
        if timezone.now() - rates.last_update_blockchain > timedelta(
                minutes=3):
            try:
                _get_blockchain_data(rates)
            except BaseException, e:
                logger.error('Error fetching blockchain data: %s' % e)
        if timezone.now() - rates.last_update_oer > timedelta(minutes=240):
            try:
                _get_oer_data(rates)
            except BaseException, e:
                logger.error('Error fetching OpenExchangeRates data: %s' % e)
    else:
        rates = Rates.create_empty()
        _get_blockchain_data(rates)
        _get_oer_data(rates)
    return rates


def _get_blockchain_data(rates):
    response = requests.get('https://blockchain.info/pt/ticker')
    content = response.content
    if Rates.is_valid_blockchain_data(content):
        rates.blockchain_data = content
        rates.last_update_blockchain = timezone.now()
        rates.save()
    else:
        logger.error('got invalid Blockchain data: %s' % content)
def _get_rates():
    q = Rates.objects.all()
    if q.count() > 0:
        rates = Rates.objects.all()[0]
        if timezone.now() - rates.last_update_blockchain > timedelta(minutes=3):
            try:
                _get_blockchain_data(rates)
            except BaseException, e:
                logger.error("Error fetching blockchain data: %s" % e)
        if timezone.now() - rates.last_update_oer > timedelta(minutes=240):
            try:
                _get_oer_data(rates)
            except BaseException, e:
                logger.error("Error fetching OpenExchangeRates data: %s" % e)
    else:
        rates = Rates.create_empty()
        _get_blockchain_data(rates)
        _get_oer_data(rates)
    return rates


def _get_blockchain_data(rates):
    response = requests.get("http://blockchain.info/pt/ticker")
    content = response.content
    if Rates.is_valid_blockchain_data(content):
        rates.blockchain_data = content
        rates.last_update_blockchain = timezone.now()
        rates.save()
    else:
        logger.error("got invalid Blockchain data: %s" % content)