예제 #1
0
def get_random_card(raridade):
	
	cartas = []
	
	while(True):
		
		cartas = None
	
		rand = get_random_number()
		
		if raridade == "Rare":
			cartas = cartas_mtg.all().filter('raridade =', raridade).filter('disponivel =',True).filter('random_number > ',rand).fetch(limit=NUMBER_OF_RARE_TO_TAKE)
			cartas = cartas + cartas_mtg.all().filter('raridade =', "Mytic").filter('disponivel =',True).filter('random_number > ',rand).fetch(limit=NUMBER_OF_MYTIC_TO_TAKE)
		else:
			cartas = cartas_mtg.all().filter('raridade =', raridade).filter('disponivel =',True).filter('random_number > ',rand).fetch(limit=NUMBER_OF_COMMON_UNCOMMON_TO_TAKE)
			
		if len(cartas) > 0:
			break

	cartas = take_out_cards_by_importance(cartas)
	
	toReturn = choice(cartas)
	
	logging.info("-------------------")
	logging.info("Nome " + str(toReturn.nome))
	logging.info("Stock " + str(toReturn.stock))
	logging.info("Importancia " + str(toReturn.importance))
	logging.info("-------------------")
	
	return toReturn
예제 #2
0
def fix_DB(request):

	edition = db_fixer_edition.all().get()
	
	if edition == None:
		edition = db_fixer_edition(edition = "")
		edition.put()
		return HttpResponse("NO ME GUSTA")

	query = cartas_mtg.all().filter('edicao =',edition.edition).filter('raridade =','Uncommon')
	
	
	last_cursor = memcache.get('DB_Fixer')
	if last_cursor:
		query.with_cursor(last_cursor)
	entries = query.fetch(50)
	cursor = query.cursor()
	memcache.set('DB_Fixer', cursor)
	
	quantidade = len(entries)
	
	for carta in entries:
		carta.stock = carta.stock + 4
		carta.put()
	
	return HttpResponse("Success " + str(quantidade))
	
예제 #3
0
def increment_card_stock(card):

    real_card = (
        cartas_mtg.all()
        .filter("nome =", card.nome)
        .filter("edicao =", card.edicao)
        .filter("cor =", card.cor)
        .filter("custo =", card.custo)
        .filter("tipo =", card.tipo)
        .get()
    )
    real_card.stock = real_card.stock + 1
    real_card.put()
def return_list_of_cards_from_request(request):	
	carrinho = request.session.get('carrinho')
	
	if carrinho == None:
		return None
	
	pais = page_users_utils.get_pais_from_request(request)
	
	carrinho = eval(carrinho)
	
	if int(carrinho['number_cards']) == 0:
		return None
	
	cards_cart = []
	
	number_cards = carrinho['number_cards']
	
	
	logging.info("number_cards " + str(number_cards))
	logging.info("total_number_cards " + str(carrinho['total_number_cards']))
	
	for card in range(number_cards):
		card_id = "card" + str(card+1)
		
		try:
			name = carrinho['cards'][card_id]['name']
			edition = carrinho['cards'][card_id]['edition']
			quantity = carrinho['cards'][card_id]['quantity']
			
			logging.info(name)
			logging.info(edition)
			logging.info(quantity)
	
			real_card = cartas_mtg.all().filter('nome =',name).filter('edicao =',edition).get()
		
			stock = real_card.stock
			real_value = real_card.real_value
			conversion = card_database_utils.real_price_by_credits(real_value,pais)
			raridade = real_card.raridade
		
			#to not use card and to add field quantity
			card_in_cart = cartas_mtg_store(name,raridade,edition,stock,real_value,conversion,quantity)
		
			cards_cart.append(card_in_cart)
		except:
			pass
			
	if cards_cart == []:
		return None
		
	return cards_cart
예제 #5
0
def prepare_get_random_card(raridade,importancia):

	cartas = []
	
	counter = 0
	importancia = importancia
	
	while(True):
	
		rand = get_random_number()
		
		if raridade == "Rare":
			cartas = cartas_mtg.all().filter('raridade =', raridade).filter('disponivel =',True).filter("importance =",importancia).filter('random_number > ',rand).fetch(limit=NUMBER_OF_RARE_TO_TAKE)
			#cartas = cartas + cartas_mtg.all().filter('raridade =', "Mytic").filter('disponivel =',True).filter("importance =",importancia).filter('random_number > ',rand).fetch(limit=NUMBER_OF_MYTIC_TO_TAKE)
		else:
			cartas = cartas_mtg.all().filter('raridade =', raridade).filter('disponivel =',True).filter("importance =",importancia).filter('random_number > ',rand).fetch(limit=NUMBER_OF_COMMON_UNCOMMON_TO_TAKE)
			
		
		if cartas == []:
			if raridade == "Rare":
				cartas = cartas_mtg.all().filter('raridade =', raridade).filter('disponivel =',True).filter("importance =",importancia).filter('random_number < ',rand).fetch(limit=NUMBER_OF_RARE_TO_TAKE)
				#cartas = cartas_mtg.all().filter('raridade =', "Mytic").filter('disponivel =',True).filter("importance =",importancia).filter('random_number < ',rand).fetch(limit=NUMBER_OF_MYTIC_TO_TAKE)
			else:
				cartas = cartas_mtg.all().filter('raridade =', raridade).filter('disponivel =',True).filter("importance =",importancia).filter('random_number < ',rand).fetch(limit=NUMBER_OF_COMMON_UNCOMMON_TO_TAKE)
				
		if cartas != []:
			break
			
		#if no card with choosen importance	
		counter	= counter + 1
		if counter == 10:
			importancia = 1
			
	toReturn = choice(cartas)
	
	return toReturn	
예제 #6
0
def check_DB(request):
	cards = cartas_mtg.all().filter('stock > ', 0)
	
	comum  = 0
	incomum = 0
	rara = 0
	
	um = 0
	dois = 0
	tres = 0
	quatro = 0
	cinco = 0
	seis = 0
	sete = 0
	oito = 0
	nove = 0
	dez = 0
	onze = 0
	doze = 0
	treze = 0
	
	um_stock = 0
	dois_stock = 0
	tres_stock = 0
	quatro_stock = 0
	cinco_stock = 0
	seis_stock = 0
	sete_stock = 0
	oito_stock = 0
	nove_stock = 0
	dez_stock = 0
	onze_stock = 0
	doze_stock = 0
	treze_stock = 0
	
	for card in cards:
		raridade = card.raridade
		stock = card.stock
		importancia = card.importance
		
		if raridade == "Rare" or raridade == "Mytic":
			rara += stock
		elif raridade == "Uncommon":
			incomum += stock
		elif raridade == "Common":
			comum += stock
			
		if importancia == 1:
			um = um + 1
			um_stock = um_stock + card.stock
		elif importancia == 2:
			dois = dois +1
			dois_stock = dois_stock + card.stock
		elif importancia == 3:
			tres = tres +1
			tres_stock = tres_stock + card.stock
		elif importancia == 4:
			quatro = quatro +1
			quatro_stock = quatro_stock + card.stock
		elif importancia == 5:
			cinco = cinco +1
			cinco_stock = cinco_stock + card.stock
		elif importancia == 6:
			seis = seis +1
			seis_stock = seis_stock + card.stock
		elif importancia == 7:
			sete = sete +1
			sete_stock = sete_stock + card.stock
		elif importancia == 8:
			oito = oito +1	
			oito_stock = oito_stock + card.stock
		elif importancia == 9:
			nove = nove +1	
			nove_stock = nove_stock + card.stock
		elif importancia == 10:
			dez = dez +1	
			dez_stock = dez_stock + card.stock
		elif importancia == 11:
			onze = onze +1	
			onze_stock = onze_stock + card.stock
		elif importancia == 12:
			doze = doze +1	
			doze_stock = doze_stock + card.stock
		elif importancia == 13:
			treze = treze +1	
			treze_stock = treze_stock + card.stock
			
	toReturn = "Comum = " + str(comum) + " Incomum = " + str(incomum) + " Rara = " + str(rara)
	
	toReturn = toReturn+ "<p></p>"

	toReturn = toReturn + "IMPORTANCIAS"
	
	toReturn = toReturn+ "<p></p>"
	
	toReturn = toReturn+ "1 = " + str(um) + " <b>//</b> Stock = " + str(um_stock) + "<p></p>"
	toReturn = toReturn+ "2 = " + str(dois) + " <b>//</b> Stock = " + str(dois_stock) + "<p></p>"
	toReturn = toReturn+ "3 = " + str(tres) + " <b>//</b> Stock = " + str(tres_stock) + "<p></p>"
	toReturn = toReturn+ "4 = " + str(quatro) + " <b>//</b> Stock = " + str(quatro_stock) + "<p></p>"
	toReturn = toReturn+ "5 = " + str(cinco) + " <b>//</b> Stock = " + str(cinco_stock) + "<p></p>"
	toReturn = toReturn+ "6 = " + str(seis) + " <b>//</b> Stock = " + str(seis_stock) + "<p></p>"
	toReturn = toReturn+ "7 = " + str(sete) + " <b>//</b> Stock = " + str(sete_stock) + "<p></p>"
	toReturn = toReturn+ "8 = " + str(oito) + " <b>//</b> Stock = " + str(oito_stock) + "<p></p>"
	toReturn = toReturn+ "9 = " + str(nove) + " <b>//</b> Stock = " + str(nove_stock) + "<p></p>"
	toReturn = toReturn+ "10 = " + str(dez) + " <b>//</b> Stock = " + str(dez_stock) + "<p></p>"
	toReturn = toReturn+ "11 = " + str(onze) + " <b>//</b> Stock = " + str(onze_stock) + "<p></p>"
	toReturn = toReturn+ "12 = " + str(doze) + " <b>//</b> Stock = " + str(doze_stock) + "<p></p>"
	toReturn = toReturn+ "13 = " + str(treze) + " <b>//</b> Stock = " + str(treze_stock) + "<p></p>"
		
			

	return toReturn
예제 #7
0
def check_DB(request):
    cards = cartas_mtg.all().filter('stock > ', 0)

    comum = 0
    incomum = 0
    rara = 0

    um = 0
    dois = 0
    tres = 0
    quatro = 0
    cinco = 0
    seis = 0
    sete = 0
    oito = 0
    nove = 0
    dez = 0
    onze = 0
    doze = 0
    treze = 0

    um_stock = 0
    dois_stock = 0
    tres_stock = 0
    quatro_stock = 0
    cinco_stock = 0
    seis_stock = 0
    sete_stock = 0
    oito_stock = 0
    nove_stock = 0
    dez_stock = 0
    onze_stock = 0
    doze_stock = 0
    treze_stock = 0

    for card in cards:
        raridade = card.raridade
        stock = card.stock
        importancia = card.importance

        if raridade == "Rare" or raridade == "Mytic":
            rara += stock
        elif raridade == "Uncommon":
            incomum += stock
        elif raridade == "Common":
            comum += stock

        if importancia == 1:
            um = um + 1
            um_stock = um_stock + card.stock
        elif importancia == 2:
            dois = dois + 1
            dois_stock = dois_stock + card.stock
        elif importancia == 3:
            tres = tres + 1
            tres_stock = tres_stock + card.stock
        elif importancia == 4:
            quatro = quatro + 1
            quatro_stock = quatro_stock + card.stock
        elif importancia == 5:
            cinco = cinco + 1
            cinco_stock = cinco_stock + card.stock
        elif importancia == 6:
            seis = seis + 1
            seis_stock = seis_stock + card.stock
        elif importancia == 7:
            sete = sete + 1
            sete_stock = sete_stock + card.stock
        elif importancia == 8:
            oito = oito + 1
            oito_stock = oito_stock + card.stock
        elif importancia == 9:
            nove = nove + 1
            nove_stock = nove_stock + card.stock
        elif importancia == 10:
            dez = dez + 1
            dez_stock = dez_stock + card.stock
        elif importancia == 11:
            onze = onze + 1
            onze_stock = onze_stock + card.stock
        elif importancia == 12:
            doze = doze + 1
            doze_stock = doze_stock + card.stock
        elif importancia == 13:
            treze = treze + 1
            treze_stock = treze_stock + card.stock

    toReturn = "Comum = " + str(comum) + " Incomum = " + str(
        incomum) + " Rara = " + str(rara)

    toReturn = toReturn + "<p></p>"

    toReturn = toReturn + "IMPORTANCIAS"

    toReturn = toReturn + "<p></p>"

    toReturn = toReturn + "1 = " + str(um) + " <b>//</b> Stock = " + str(
        um_stock) + "<p></p>"
    toReturn = toReturn + "2 = " + str(dois) + " <b>//</b> Stock = " + str(
        dois_stock) + "<p></p>"
    toReturn = toReturn + "3 = " + str(tres) + " <b>//</b> Stock = " + str(
        tres_stock) + "<p></p>"
    toReturn = toReturn + "4 = " + str(quatro) + " <b>//</b> Stock = " + str(
        quatro_stock) + "<p></p>"
    toReturn = toReturn + "5 = " + str(cinco) + " <b>//</b> Stock = " + str(
        cinco_stock) + "<p></p>"
    toReturn = toReturn + "6 = " + str(seis) + " <b>//</b> Stock = " + str(
        seis_stock) + "<p></p>"
    toReturn = toReturn + "7 = " + str(sete) + " <b>//</b> Stock = " + str(
        sete_stock) + "<p></p>"
    toReturn = toReturn + "8 = " + str(oito) + " <b>//</b> Stock = " + str(
        oito_stock) + "<p></p>"
    toReturn = toReturn + "9 = " + str(nove) + " <b>//</b> Stock = " + str(
        nove_stock) + "<p></p>"
    toReturn = toReturn + "10 = " + str(dez) + " <b>//</b> Stock = " + str(
        dez_stock) + "<p></p>"
    toReturn = toReturn + "11 = " + str(onze) + " <b>//</b> Stock = " + str(
        onze_stock) + "<p></p>"
    toReturn = toReturn + "12 = " + str(doze) + " <b>//</b> Stock = " + str(
        doze_stock) + "<p></p>"
    toReturn = toReturn + "13 = " + str(treze) + " <b>//</b> Stock = " + str(
        treze_stock) + "<p></p>"

    return toReturn
def change_quantity_card(request):
	carrinho = request.session.get('carrinho')
	
	if carrinho == None:
		return None
	
	nome = None
	edicao = None
	raridade = None
	quantity = None
		
	try:
		nome = request.POST['nome']
	except:
		logging.info("nome")
		return HttpResponse("Nome em falta")
	try:
		edicao = request.POST['edicao']
	except:
		logging.info("edicao")
		return HttpResponse("Edicao em falta")
	try:
		raridade = request.POST['raridade']
	except:
		logging.info("raridade")
		return HttpResponse("Raridade em falta")
	try:
		quantity = int(request.POST['quantity'])
	except:
		logging.info("quantidade")
		return HttpResponse("Quantidade em falta")

	carta_real = cartas_mtg.all().filter('nome =',name).filter('edicao =',edition).get()
	
	if carta_real == None:
		return HttpResponse("Carta invalida")
		
	if quantity < 0 or quantity > constants.MAX_NUMBER_CARDS_PER_USER:
		return HttpResponse("A quantidade tem de ser um valor entre 0 e  "+ str(constants.MAX_NUMBER_CARDS_PER_USER) + " unidades")
		
	if quantity > carta_real.stock:
		return HttpResponse("Apenas existe " + str(carta_real.stock) + " em stock")
			
	try:		
		carrinho = eval(carrinho)
	except:
		carrinho = { "number_cards":0, "total_number_cards":0, "cards":{} }
		request.session['carrinho'] = str(carrinho)
		return HttpResponse("Carrinho Inv&aacute;lida")
		
		
	number_cards = carrinho['number_cards']
	
	for card in range(number_cards):
		card_id = "card" + str(card+1)
		
		try:
			if (carrinho['cards'][card_id]['name'] == nome) and (carrinho['cards'][card_id]['edition'] == edicao):
				if quantity != 0:
					#valor para tirar ao total_number_cards (diferenca entre a quantidade existente e a nova)
					diff = int(carrinho['cards'][card_id]['quantity']) - quantity
					carrinho['total_number_cards'] = int(carrinho['total_number_cards']) - diff
					carrinho['cards'][card_id]['quantity'] = quantity
				if quantity == 0:
					carrinho['total_number_cards'] = int(carrinho['total_number_cards']) - int(carrinho['cards'][card_id]['quantity']) 
					#carrinho['number_cards'] = int(carrinho['number_cards']) - 1
					del carrinho['cards'][card_id]
					if int(carrinho['total_number_cards']) == 0:
						empty_store_cart(request)
						return None
				break
		except:
			pass
			
	request.session['carrinho'] = str(carrinho)
예제 #9
0
def change_user_cards(request):

    rand = random_utils.get_random_number()

    cards_rare = (
        cartas_mtg.all()
        .filter("raridade =", "Rare")
        .filter("disponivel =", True)
        .filter("importance =", 13)
        .filter("random_number > ", rand)
        .fetch(10)
    )

    if len(cards_rare) < 10:
        cards_rare = cards_rare + cartas_mtg.all().filter("raridade =", "Rare").filter("disponivel =", True).filter(
            "importance =", 12
        ).filter("random_number > ", rand).fetch(10 - len(cards_rare))
    if len(cards_rare) < 10:
        cards_rare = cards_rare + cartas_mtg.all().filter("raridade =", "Rare").filter("disponivel =", True).filter(
            "importance =", 11
        ).filter("random_number > ", rand).fetch(10 - len(cards_rare))
    if len(cards_rare) < 10:
        cards_rare = cards_rare + cartas_mtg.all().filter("raridade =", "Rare").filter("disponivel =", True).filter(
            "importance =", 10
        ).filter("random_number > ", rand).fetch(10 - len(cards_rare))
    if len(cards_rare) < 10:
        cards_rare = cards_rare + cartas_mtg.all().filter("raridade =", "Rare").filter("disponivel =", True).filter(
            "importance =", 1
        ).filter("random_number > ", rand).fetch(10 - len(cards_rare))

    cards_uncommon = (
        cartas_mtg.all()
        .filter("raridade =", "Uncommon")
        .filter("disponivel =", True)
        .filter("importance =", 9)
        .filter("random_number > ", rand)
        .fetch(5)
    )
    if len(cards_uncommon) < 5:
        cards_uncommon = cards_uncommon + cartas_mtg.all().filter("raridade =", "Uncommon").filter(
            "disponivel =", True
        ).filter("importance =", 8).filter("random_number > ", rand).fetch(5 - len(cards_uncommon))
    if len(cards_uncommon) < 5:
        cards_uncommon = cards_uncommon + cartas_mtg.all().filter("raridade =", "Uncommon").filter(
            "disponivel =", True
        ).filter("importance =", 7).filter("random_number > ", rand).fetch(5 - len(cards_uncommon))
    if len(cards_uncommon) < 5:
        cards_uncommon = cards_uncommon + cartas_mtg.all().filter("raridade =", "Uncommon").filter(
            "disponivel =", True
        ).filter("importance =", 6).filter("random_number > ", rand).fetch(5 - len(cards_uncommon))
    if len(cards_uncommon) < 5:
        cards_uncommon = cards_uncommon + cartas_mtg.all().filter("raridade =", "Uncommon").filter(
            "disponivel =", True
        ).filter("importance =", 5).filter("random_number > ", rand).fetch(5 - len(cards_uncommon))
    if len(cards_uncommon) < 5:
        cards_uncommon = cards_uncommon + cartas_mtg.all().filter("raridade =", "Uncommon").filter(
            "disponivel =", True
        ).filter("importance =", 1).filter("random_number > ", rand).fetch(5 - len(cards_uncommon))

    cards_common = (
        cartas_mtg.all()
        .filter("raridade =", "Common")
        .filter("disponivel =", True)
        .filter("importance =", 4)
        .filter("random_number > ", rand)
        .fetch(5)
    )
    if len(cards_common) < 5:
        cards_common = cards_common + cartas_mtg.all().filter("raridade =", "Common").filter(
            "disponivel =", True
        ).filter("importance =", 3).filter("random_number > ", rand).fetch(5 - len(cards_common))
    if len(cards_common) < 5:
        cards_common = cards_common + cartas_mtg.all().filter("raridade =", "Common").filter(
            "disponivel =", True
        ).filter("importance =", 2).filter("random_number > ", rand).fetch(5 - len(cards_common))
    if len(cards_common) < 5:
        cards_common = cards_common + cartas_mtg.all().filter("raridade =", "Common").filter(
            "disponivel =", True
        ).filter("importance =", 1).filter("random_number > ", rand).fetch(5 - len(cards_common))

    cards = cards_rare + cards_uncommon + cards_common

    if len(cards) == 20:
        # delete
        q = user_cards.all().fetch(20)
        for card in q:
            card.delete()

            # add
        for card in cards:
            card_toAdd = user_cards(name_card=card.nome)
            card_toAdd.put()

    return HttpResponse("sucess")
예제 #10
0
def decrement_card_stock_store(nome, edicao, quantity):

    real_card = cartas_mtg.all().filter("nome =", nome).filter("edicao =", edicao).get()
    real_card.stock = real_card.stock - int(quantity)
    real_card.put()
예제 #11
0
def add_card_to_db(request):

    name = ""
    colour = ""
    cost = ""
    type = ""
    power_resistance = ""
    text = ""
    rarity = ""
    edition = ""
    quantidade = None
    importancia = None

    try:
        name = request.POST["name"]
        colour = request.POST["colour"]
        cost = request.POST["cost"]
        type = request.POST["type"]
        power_resistance = request.POST["power_resistance"]
        text = request.POST["text"]
        rarity = request.POST["rarity"]
        edition = request.POST["edition"]
        quantidade = int(request.POST["stock"])
        importancia = int(request.POST["importance"])

    except:
        return HttpResponse("Erro nos dados da carta " + name)

    if len(text) > 500:
        logging.info(name)
        text = text[:500]

        # cleans % from text
    text = text.replace("%", "")

    if rarity == "R" or rarity == "R // R":
        rarity = "Rare"

    if rarity == "M" or rarity == "M // M":
        rarity = "Mytic"

    if rarity == "U" or rarity == "U // U":
        rarity = "Uncommon"

    if rarity == "C" or rarity == "C // C":
        rarity = "Common"

    carta_comparacao = cartas_mtg.all().filter("nome =", name).filter("edicao =", edition).get()

    if carta_comparacao != None:
        return HttpResponse("Carta jah existe " + name)

    card = cartas_mtg(
        nome=name,
        cor=colour,
        custo=cost,
        tipo=type,
        poder_resistencia=power_resistance,
        texto=text,
        raridade=rarity,
        random_number=random_utils.get_random_number(),
        stock=int(quantidade),
        importance=int(importancia),
        edicao=edition,
    )

    card.put_DB()

    return HttpResponse("Success")