Ejemplo n.º 1
0
def update_price_item(item_id, force=False):
    try:
        item_price = ItemPrice.objects.get(pk=item_id)
    except ItemPrice.DoesNotExist:
        item_price = ItemPrice(id=item_id)
    price = 0.0
    try:
        r = requests.get('http://api.eve-central.com/api/marketstat?typeid=' + str(item_id))
        root = ET.fromstring(r.text)
        all = root[0][0].find('all')
        price = all.find('median').text
        sleep(1)
    except:
        pass
    item_price.price = price
    item_price.save()
    return price
Ejemplo n.º 2
0
def update_fit(fit_id):
    try:
        doctrine_fit = DoctrineFit.objects.get(pk=fit_id)
    except DoctrineFit.DoesNotExist:
        return False
    if doctrine_fit.updated_at > timezone.now():
        return False
    fit = json.loads(doctrine_fit.fit)
    price = Decimal(0.0)
    try:
        p = ItemPrice.objects.get(item_id=fit['ship']['ship_id'])
    except ItemPrice.DoesNotExist:
        p = ItemPrice()
        p.item = InvType.objects.get(pk=fit['ship']['ship_id'])
        p.update_price(force=True)
    p.update_price(force=True)
    price += p.price
    for m in fit['modules']:
        try:
            p = ItemPrice.objects.get(item_id=m['id'])
        except ItemPrice.DoesNotExist:
            p = ItemPrice()
            p.item = InvType.objects.get(pk=m['id'])
            p.update_price(force=True)
        p.update_price(force=True)
        price += p.price
    for d in fit['drones']:
        try:
            p = ItemPrice.objects.get(item_id=d['id'])
        except ItemPrice.DoesNotExist:
            p = ItemPrice()
            p.item = InvType.objects.get(pk=m['id'])
            p.update_price(force=True)
        p.update_price(force=True)
        price += (p.price * d['amount'])
    doctrine_fit.price = price
    doctrine_fit.save()
Ejemplo n.º 3
0
def update_fit(fit_id):
    try:
        doctrine_fit = DoctrineFit.objects.get(pk=fit_id)
    except DoctrineFit.DoesNotExist:
        return False
    if doctrine_fit.updated_at > timezone.now():
        return False
    fit = json.loads(doctrine_fit.fit)
    price = Decimal(0.0)
    try:
        p = ItemPrice.objects.get(item_id=fit['ship']['ship_id'])
    except ItemPrice.DoesNotExist:
        p = ItemPrice()
        p.item = InvType.objects.get(pk=fit['ship']['ship_id'])
        p.update_price(force=True)
    p.update_price(force=True)
    price += p.price
    for m in fit['modules']:
        try:
            p = ItemPrice.objects.get(item_id=m['id'])
        except ItemPrice.DoesNotExist:
            p = ItemPrice()
            p.item = InvType.objects.get(pk=m['id'])
            p.update_price(force=True)
        p.update_price(force=True)
        price += p.price
    for d in fit['drones']:
        try:
            p = ItemPrice.objects.get(item_id=d['id'])
        except ItemPrice.DoesNotExist:
            p = ItemPrice()
            p.item = InvType.objects.get(pk=m['id'])
            p.update_price(force=True)
        p.update_price(force=True)
        price += (p.price * d['amount'])
    doctrine_fit.price = price
    doctrine_fit.save()