Exemple #1
0
	def straight(self,unique_vals):
		straight_cards = []

		##########
		# For every 5-card window, check to see if cards are in
		# numerical order.
		if len(unique_vals) >= 5:
			straight_cards = self.straight_test_once( unique_vals )

			##########
			# If the straight is a low-ace straight, the above will not find it.
			# We check for a low-ace straight if...
			# 1. We didn't find a straight with the first check (b.c. if we did it is higher than low-ace)
			# 2. There is at least one ace in the list.
			# If these are met, we move the ace to the bottom of the list, change its
			# value from 12 to -1 (same mod 13), and check again.
			if len(straight_cards)==0 and unique_vals[-1].value==12:
				ace_integer = unique_vals[-1].integer_val
				temp_ace = Card(ace_integer)
				temp_ace.value = -1
				# ^^This card is now mal-formed. Its integer value does not match suit*13+value,
				# and it has a value not between 0 and 12. Still, it will work to test a straight,
				# and then we will throw it away.

				temp_vals = [temp_ace]+unique_vals[:-1]

				temp_straight_cards = self.straight_test_once( temp_vals )

				##########
				# If we find a straight now, we know it was because we moved the ace to the bottom
				# We create a proper card list with the ace at the bottom, and the next four cards.
				if len(temp_straight_cards)!=0:
					straight_cards = unique_vals[-1:] + unique_vals[:4]

		return straight_cards
Exemple #2
0
 def testRankEquivalent(self):
     c = Card(4,'H')
     c1 = Card(4, 'D')
     self.assertTrue(c.rankEquivalent(c1),'testCard:testRankEq:Cards should have same rank')
     c = Card('J','H')
     c1 = Card('K','D')
     self.assertFalse(c.rankEquivalent(c1),'testCard:testRankEq:Cards should not have same rank')
Exemple #3
0
def init_cards():
    global deck, p_hand, c_hand, up_card, active_suit
    deck = []
    for suit in range(1, 5):
        for rank in range(1, 14):
            new_card = Card(suit, rank)
            if rank == 8:
                new_card.value = 50
            deck.append(new_card)

    p_hand = []
    for cards in range(0, 5):
        card = random.choice(deck)
        p_hand.append(card)
        deck.remove(card)
    
    c_hand = []    
    for cards in range(0, 5):
        card = random.choice(deck)
        c_hand.append(card)
        deck.remove(card)
        
    card = random.choice(deck)
    deck.remove(card)
    up_card  = card
    active_suit = up_card.suit
Exemple #4
0
 def handle_info(self, line):
     logging.info("info: '%s'", line)
     if line.startswith("|INFO|end game|"):
         logging.info("Received 'end game' message")
         return False
     elif line.startswith("|INFO|start game|"):
         return True
     elif line.startswith("|INFO|start hand|"):
         return True
     elif line.startswith("|INFO|end hand|"):
         return True
     elif line.startswith("|INFO|start trick|"):
         self.first_card_of_trick = None
     elif line.startswith("|INFO|end trick|"):
         return True
     elif line.startswith("|INFO|bad card|"):
         return True
     elif line.startswith("|INFO|played|"):
         ### if this is the first card of the trick, figure out what the suit is
         if self.first_card_of_trick is None:
             self.first_card_of_trick = Card.fromString(line.split("|")[4])
             logging.info("Got first card of trick: %s", self.first_card_of_trick)
     elif line.startswith("|INFO|cards|"):
         card_text = line.split("|")[3]
         logging.info("card_text:%s" % card_text)
         self.cards = [Card.fromString(x) for x in card_text.split()]
     else:
         logging.error("Unknown incoming line: %s", line)
         return False
     return True
Exemple #5
0
    def _deckArrived(self, players, ourNr, ourDeck):
        """
        The network give us our number and our deck. Display it on the table
        """
        assert(isinstance(ourNr, int))
        assert(isinstance(ourDeck, list))
        self.Playing.emit()

        self.imageDeck = {}
        self.playerNr = ourNr

        # Identify our place on the table
        frame = None
        if ourNr == 0:
            frame = self.topCard_2
        elif ourNr == 1:
            frame = self.leftCard_2
        elif ourNr == 2:
            frame = self.downCard_2
        elif ourNr == 3:
            frame = self.rightCard_2

        frame.setFrameShadow(QFrame.Raised)

        # Set names
        for player in players.split(";")[:-1]:
            nr = int(player.split(":")[0])
            name = str(player.split(":")[1])
            if nr == 0:
                self.labelTop.setText(name)
            elif nr == 1:
                self.labelLeft.setText(name)
            elif nr == 2:
                self.labelDown.setText(name)
            elif nr == 3:
                self.labelRight.setText(name)

        # Do our ui deck
        for card in ourDeck:
            label = CardContainer(self)
            imageCard = Card(card, label)
            label.cardClicked.connect(self._cardClicked)

            imageCard.load("media/" + card + ".gif")
            self.imageDeck[card] = label
            label.setPixmap(imageCard)
            self.allCards.addWidget(label)

        self.sendCardButton.setEnabled(True)
        self.state = "3C"
Exemple #6
0
 def setUp(self):
     self.card = Card()
     
     self.connectionsChanged_count = 0
     def connectionsChanged_spy():
         self.connectionsChanged_count += 1
     self.card.connectionsChanged.connect(connectionsChanged_spy)
Exemple #7
0
 def test_generateDeck(self):
     deck = Card.generateDeck()
     self.assertEqual(type(deck), list)
     self.assertEqual(52, len(deck))
     for kind in self.kinds:
         for value in self.values:
             self.assertTrue(Card(kind+value) in deck)
Exemple #8
0
class TestCard(unittest.TestCase):
    def setUp(self):
        self.card = Card('HQ')
        self.kinds = ['S', 'C', 'D', 'H']
        self.values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']

    def test_value(self):
        self.assertEqual(self.card.value(), 'Q')

    def test_kind(self):
        self.assertEqual(self.card.kind(), 'H')

    def test_valueName(self):
        self.assertEqual(self.card.valueName(), 'Queen')

    def test_kindName(self):
        self.assertEqual(self.card.kindName(), 'Hearts')

    def test_fullName(self):
        self.assertEqual(self.card.fullName(), 'The Queen of Hearts')

    def test_str(self):
        self.assertEqual(str(self.card), 'HQ')

    def test_invalidKind(self):
        self.assertRaises(ValueError, Card, 'P8')

    def test_invalidValue(self):
        self.assertRaises(ValueError, Card, 'DB')

    def test_generateDeck(self):
        deck = Card.generateDeck()
        self.assertEqual(type(deck), list)
        self.assertEqual(52, len(deck))
        for kind in self.kinds:
            for value in self.values:
                self.assertTrue(Card(kind+value) in deck)

    def test_sorting(self):
        deck = Card.generateDeck()
        shuffle(deck)
        deck = sorted(deck)
        for i in range(0, 52-1):
            if self.kinds.index(deck[i].kind()) == self.kinds.index(deck[i+1].kind()):
                self.assertTrue(self.values.index(deck[i].value()) < self.values.index(deck[i+1].value()))
            else:
                self.assertTrue(self.kinds.index(deck[i].kind()) < self.kinds.index(deck[i+1].kind()))
Exemple #9
0
 def test_constructor_with_endpoint_list(self):
     """ You can pass in a list of endpoint connections to the constructor """
     # arrange
     endpoint_connections = [ [0, 1], [3, 4, 5] ]
     # act
     self.card = Card(endpoint_connections)
     # assert
     self.assertEqual(self.card.getConnectedEndpoints(), endpoint_connections)
Exemple #10
0
 def test_sorting(self):
     deck = Card.generateDeck()
     shuffle(deck)
     deck = sorted(deck)
     for i in range(0, 52-1):
         if self.kinds.index(deck[i].kind()) == self.kinds.index(deck[i+1].kind()):
             self.assertTrue(self.values.index(deck[i].value()) < self.values.index(deck[i+1].value()))
         else:
             self.assertTrue(self.kinds.index(deck[i].kind()) < self.kinds.index(deck[i+1].kind()))
Exemple #11
0
 def test_ne_with_identical_cards(self):
     """ Ensure that cards which are the same evaluate as equal """
     # arrange
     endpoints = [ [0, 1], [2, 5] ]
     self.card = Card(endpoints)
     card2 = Card(endpoints)
     # act
     not_equal = (self.card != card2)
     # assert
     self.assertFalse(not_equal)
Exemple #12
0
def init_cards():

    global deck, p_hand, c_hand, up_card, active_suit
    print "init cards"
    deck = []                                           
    for suit_id in range(1, 5):                           
        for rank_id in range(1, 14):
            
            new_card=Card(suit_id, rank_id)
            
            if new_card.rank_id == 8:
                
                new_card.value = 50
            
            deck.append(new_card)             

    p_hand=[]
    for nhand in range(0,5):
        a=random.choice(deck)
        p_hand.append(a)
        deck.remove(a)
    
    c_hand=[]
    for nhand in range(0,5):
        a=random.choice(deck)
        c_hand.append(a)
        deck.remove(a)
    
    a=random.choice(deck)
    print "a.suit = ", a.suit
    if a.suit ==0:
        active_suit = "Diamonds"                                  
    if a.suit == 1:                                            
        active_suit = "Hearts"                                    
    if a.suit == 2:                                            
        active_suit = "Spades"                                    
    if a.suit == 3:                                            
        active_suit = "Clubs"
    
    #print "log: init: active_suit = ", active_suit
    up_card=a
    deck.remove(a)
Exemple #13
0
def init_cards():
    deck = []
    for suit in range(1, 5):
        for rank in range(1, 14):
            new_card = Card(suit, rank)
            if new_card.rank == 8:
                new_card.value = 50
            deck.append(new_card)
    print "一副牌,4个花色52张,不含大小王,生成完毕。"

    p_hand = c_hand = []
    for init_roll in range(0,5):
        card_one = random.choice(deck)
        print "发牌" + card_one.long_name
        p_hand.append(card_one)
        deck.remove(card_one)
        card_two = random.choice(deck)
        print "发牌" + card_two.long_name
        c_hand.append(card_tow)
        deck.remove(card_two)
Exemple #14
0
    def _cardPlayed(self, playerNr, playerName, card):
        """
        The player played a card.
        If the user don't want updates, simply memorize it. Else, we need
        to display (on the right place) the card played.
        """
        card = str(card)
        assert(isinstance(playerNr, int))

        if self.mustMemHand:
            self.cardPlayedInHand[playerNr] = (playerName, card,)
            return

        # If we are not obs and we play a card, remove it from the
        # deck displayed
        if not self.isObs and playerNr == self.playerNr:
            assert(card in self.imageDeck)
            cardContainer = self.imageDeck.pop(card)
            self.allCards.removeWidget(cardContainer)
            cardContainer.deleteLater()

        # Make a new visible card and place it on the table
        label = CardContainer(self)
        imageCard = Card(card, label)
        imageCard.load("media/" + card + ".gif")
        label.setPixmap(imageCard)

        assert(playerNr <= 3 and playerNr >= 0)
        if playerNr == 0:
            self.topCard.addWidget(label)
            self.labelTop.setText(playerName)
        elif playerNr == 1:
            self.leftCard.addWidget(label)
            self.labelLeft.setText(playerName)
        elif playerNr == 2:
            self.downCard.addWidget(label)
            self.labelDown.setText(playerName)
        elif playerNr == 3:
            self.rightCard.addWidget(label)
            self.labelRight.setText(playerName)
 def test_Card_value(self):
     c1 = Card(7, 3)
     self.assertEqual(8, c1.value())
     c2 = Card(12, 1)
     self.assertEqual(10, c2.value(face_cards_same=True))
     c3 = Card(0, 0)
     self.assertEqual(11, c3.value(ace_high=True))
Exemple #16
0
    def _cArrived(self, deck):
        """
        The network inform us that a new deck, with the 3 cards received
        from the initial passing, has arrived.
        """
        assert(isinstance(deck, list))
        # TODO: Sto rifacendo tutto da 0. Non sarebbe meglio fare un 
        # update del vecchio?
        for v in self.imageDeck.values():
            v.deleteLater()
        self.imageDeck.clear()

        for card in deck:
            label = CardContainer(self)
            imageCard = Card(card, label)
            label.cardClicked.connect(self._cardClicked)

            imageCard.load("media/" + card + ".gif")
            self.imageDeck[card] = label
            label.setPixmap(imageCard)
            self.allCards.addWidget(label)

        self.state = "P"
    def calculate_best_mapping(self, num_cards):
        """Iterates through a full suite
        """
        cards = Card.full_deck()
        mapping = {}

        for hand in itertools.combinations(cards, num_cards):
            (best_hand, score) = HandBuilder(hand).find_hand()
            mapping[hand] = best_hand

        outfile = 'best_hand_{num}.pickle'.format(num=num_cards)
        outf = open(outfile, 'wb')
        pickle.dump(mapping, outf)
        outf.close()
Exemple #18
0
 def __init__(self, game, col, row, suit='', fan='', show_count='', on_touch=None):
     self.suit = suit
     self.xstep = game.fan_pile if fan == 'right' else 0
     self.ystep = game.fan_pile if fan == 'down' else 0
     Logger.debug("Cards: new pile type=%s pos=%d %d fan=%s %d %d" % 
                 (self.type, col, row, fan, self.xstep, self.ystep))
     self.game = game
     self.layout = game.layout
     self.csize = game.card_size
     self.x, self.y = game.pos(col, row)
     self.xpos, self.ypos = self.x, self.y
     self.widgets = []
     self.counter = None
     self.draw_base(Card.base_image(suit), on_touch, show_count)
     self.clear(1)
Exemple #19
0
    def importQAFile(self, file, clean=True):
        """Import cards from given question&answer file.
        @param file can be file name or file like object
        """
        self.emit(SIGNAL('modelAboutToBeReset()'))
        self._checkActive()
        if isstring(file):
            file = open(file, 'rt')
        if clean:
            self.cards.deleteAllCards()
        prefix = ''
        last_prefix = ''
        card = Card()
        for line in file.readlines():
            if line.upper().startswith('Q:') or line.upper().startswith('A:'):
                last_prefix = prefix
                prefix = line[:2].upper()
                line = line[3:]
                # if new card then recreate
                if prefix == 'Q:' and prefix != last_prefix:
                    if not card.isEmpty():
                        self.cards.addCard(card, False)
                    card = Card()
                if line.strip() != '':
                    if prefix == 'Q:':
                        card.question += line
                    else: # prefix == a
                        card.answer += line
        # add last card
        if not card.isEmpty():
            self.cards.addCard(card)

        # TODO do it in a real transaction way
        # in case of error do a rollback
        self.cards.commit()
        self.reset()
Exemple #20
0
def test_less_than():
    c1 = Card("a task")
    c2 = Card("b task")
    assert c1 < c2
Exemple #21
0
def test_xpass():
    c1 = Card("a task")
    c2 = Card("a task")
    assert c1 == c2
Exemple #22
0
	def best_string(self):
		return self.best_hand.string(), Card.list_string( self.best_hand.cards )
Exemple #23
0
import random

from cards import Card

baraja = []
for palo in [Card.CLUB, Card.DIAMONDS, Card.SPADES, Card.HEARTS]:
    for valor in range(1, 14):
        baraja.append(Card(palo, valor))

print("Voy a elegir una carta al azar")
card = ...
print(card)
 def test_Card_num_ranks(self):
     self.assertEqual(Card.num_ranks(), 13)
Exemple #25
0
    def test_2_AddAndRemove(self):
        hand = Hand([Card(), Card(2, 11), Card(1, 1)])
        cards_str0 = [c.__str__() for c in hand.cards]
        #test for adding an existing card
        card = Card()
        self.assertIs(hand.add_card(card), None)
        cards_str1 = [c.__str__() for c in hand.cards]
        self.assertEqual(set(cards_str0), set(cards_str1))

        #test for adding a card that doesn't exist
        card2 = Card(3, 13)
        self.assertIs(hand.add_card(card2), None)
        cards_str2 = [c.__str__() for c in hand.cards]
        self.assertIn(card2.__str__(), cards_str2)
        self.assertTrue(len(cards_str2) - len(cards_str1) == 1)
        cards_str2.remove(card2.__str__())
        self.assertEqual(set(cards_str1), set(cards_str2))
        cards_str2 = [c.__str__() for c in hand.cards]

        #test for removing a card that exists
        self.assertEqual(card2.__str__(), hand.remove_card(card2).__str__())
        cards_str3 = [c.__str__() for c in hand.cards]
        self.assertTrue(len(cards_str2) - len(cards_str3) == 1)
        self.assertNotIn(card2.__str__(), cards_str3)
        cards_str2.remove(card2.__str__())
        self.assertEqual(set(cards_str3), set(cards_str2))
        cards_str2 = [c.__str__() for c in hand.cards]

        #test for removing a card that doesn't exist
        card3 = Card(1, 8)
        self.assertIs(hand.remove_card(card3), None)
        cards_str4 = [c.__str__() for c in hand.cards]
        self.assertEqual(len(cards_str3), len(cards_str4))
        self.assertEqual(set(cards_str3), set(cards_str4))
 def test_finish_from_todo(self, cards_db):
     i = cards_db.add_card(Card("foo", state="todo"))
     cards_db.finish(i)
     c = cards_db.get_card(i)
     assert c.state == "done"
Exemple #27
0
def test_create_card():
    card = Card()
    assert isinstance(card, Card)
Exemple #28
0
def sync_from_server(data):
    # print('sync from server')
    # start upload text
    # print(data)
    # print(data['rows_to_create'])
    if int(data['rows_to_create']) > 0:
        updates = data['updates']
        if 'addresses' in updates:
            for addresses in updates['addresses']:
                address = Address()
                address.address_id = addresses['id']
                address.user_id = addresses['user_id']
                address.name = addresses['name']
                address.street = addresses['street']
                address.suite = addresses['suite']
                address.city = addresses['city']
                address.state = addresses['state']
                address.zipcode = addresses['zipcode']
                address.primary_address = addresses['primary_address']
                address.concierge_name = addresses['concierge_name']
                address.concierge_number = addresses['concierge_number']
                address.status = addresses['status']
                address.deleted_at = addresses['deleted_at']
                address.created_at = addresses['created_at']
                address.updated_at = addresses['updated_at']
                # check to see if color_id already exists and update

                count_address = address.where({'address_id': address.address_id})
                if len(count_address) > 0 or address.deleted_at:
                    for data in count_address:
                        address.id = data['id']
                        if address.deleted_at:
                            address.delete()
                        else:
                            address.update_special()
                else:
                    address.add_special()
            address.close_connection()
 
        if 'cards' in updates:
            for cards in updates['cards']:
                card = Card()
                card.card_id = cards['id']
                card.company_id = cards['company_id']
                card.user_id = cards['user_id']
                card.profile_id = cards['profile_id']
                card.payment_id = cards['payment_id']
                card.root_payment_id = cards['root_payment_id']
                card.street = cards['street']
                card.suite = cards['suite']
                card.city = cards['city']
                card.state = cards['state']
                card.zipcode = cards['zipcode']
                card.exp_month = cards['exp_month']
                card.exp_year = cards['exp_year']
                card.status = cards['status']
                card.deleted_at = cards['deleted_at']
                card.created_at = cards['created_at']
                card.updated_at = cards['updated_at']
                # check to see if color_id already exists and update

                count_card = card.where({'card_id': card.card_id})
                if len(count_card) > 0 or card.deleted_at:
                    for data in count_card:
                        card.id = data['id']
                        if card.deleted_at:
                            card.delete()
                        else:
                            card.update_special()
                else:
                    card.add_special()
            card.close_connection()
        
        if 'colors' in updates:
            for colors in updates['colors']:
                color = Colored()
                color.color_id = colors['id']
                color.company_id = colors['company_id']
                color.color = colors['color']
                color.name = colors['name']
                color.ordered = colors['ordered']
                color.status = colors['status']
                color.deleted_at = colors['deleted_at']
                color.created_at = colors['created_at']
                color.updated_at = colors['updated_at']
                # check to see if color_id already exists and update

                count_color = color.where({'color_id': color.color_id})
                if len(count_color) > 0 or color.deleted_at:
                    for data in count_color:
                        color.id = data['id']
                        if color.deleted_at:
                            color.delete()
                        else:
                            color.update_special()
                else:
                    color.add_special()
            color.close_connection()

        if 'companies' in updates:
            for companies in updates['companies']:
                company = Company()
                company.company_id = companies['id']
                company.name = companies['name']
                company.street = companies['street']
                company.city = companies['city']
                company.state = companies['state']
                company.zip = companies['zip']
                company.email = companies['email']
                company.phone = companies['phone']
                company.store_hours = companies['store_hours']
                company.turn_around = companies['turn_around']
                company.api_token = companies['api_token']
                company.payment_gateway_id = companies['payment_gateway_id']
                company.payment_api_login = companies['payment_api_login']
                company.deleted_at = companies['deleted_at']
                company.created_at = companies['created_at']
                company.updated_at = companies['updated_at']
                company.server_at = now
                count_company = company.where({'company_id': company.company_id})
                if len(count_company) > 0 or company.deleted_at:
                    for data in count_company:
                        company.id = data['id']
                        if company.deleted_at:
                            company.delete()
                        else:
                            company.update_special()
                else:
                    company.add_special()
            company.close_connection()
            
        if 'credits' in updates:
            for credits in updates['credits']:
                credit = Credit()
                credit.credit_id = credits['id']
                credit.employee_id = credits['employee_id']
                credit.customer_id = credits['customer_id']
                credit.amount = credits['amount']
                credit.reason = credits['reason']
                credit.status = credits['status']
                credit.deleted_at = credits['deleted_at']
                credit.created_at = credits['created_at']
                credit.updated_at = credits['updated_at']
                # check to see already exists and update

                count_credit = credit.where({'credit_id': credit.credit_id})
                if len(count_credit) > 0 or credit.deleted_at:
                    for data in count_credit:
                        credit.id = data['id']
                        if credit.deleted_at:
                            credit.delete()
                        else:
                            credit.update_special()
                else:
                    credit.add_special()
            credit.close_connection()
        if 'custids' in updates:
            for custids in updates['custids']:
                custid = Custid()
                custid.cust_id = custids['id']
                custid.customer_id = custids['customer_id']
                custid.company_id = custids['company_id']
                custid.mark = custids['mark']
                custid.status = custids['status']
                custid.deleted_at = custids['deleted_at']
                custid.created_at = custids['created_at']
                custid.updated_at = custids['updated_at']
                count_custid = custid.where({'cust_id': custids['id']})
                if len(count_custid) > 0 or custid.deleted_at:
                    for data in count_custid:
                        custid.id = data['id']
                        if custid.deleted_at:
                            custid.delete()
                        else:
                            custid.update_special()
                else:
                    custid.add_special()
            custid.close_connection()

        if 'deliveries' in updates:
            for deliveries in updates['deliveries']:
                delivery = Delivery()
                delivery.delivery_id = deliveries['id']
                delivery.company_id = deliveries['company_id']
                delivery.route_name = deliveries['route_name']
                delivery.day = deliveries['day']
                delivery.delivery_limit = deliveries['limit']
                delivery.start_time = deliveries['start_time']
                delivery.end_time = deliveries['end_time']
                delivery.zipcode = deliveries['zipcode']
                delivery.blackout = deliveries['blackout']
                delivery.status = deliveries['status']
                delivery.deleted_at = deliveries['deleted_at']
                delivery.created_at = deliveries['created_at']
                delivery.updated_at = deliveries['updated_at']
                count_delivery = delivery.where({'delivery_id': delivery.delivery_id})
                if len(count_delivery) > 0 or delivery.deleted_at:
                    for data in count_delivery:
                        delivery.id = data['id']
                        if delivery.deleted_at:
                            delivery.delete()
                        else:
                            delivery.update_special()
                else:
                    delivery.add_special()
            delivery.close_connection()

        if 'discounts' in updates:
            for discounts in updates['discounts']:
                discount = Discount()
                discount.discount_id = discounts['id']
                discount.company_id = discounts['company_id']
                discount.inventory_id = discounts['inventory_id']
                discount.inventory_item_id = discounts['inventory_item_id']
                discount.name = discounts['name']
                discount.type = discounts['type']
                discount.discount = discounts['discount']
                discount.rate = discounts['rate']
                discount.end_time = discounts['end_time']
                discount.start_date = discounts['start_date']
                discount.end_date = discounts['end_date']
                discount.status = discounts['status']
                discount.deleted_at = discounts['deleted_at']
                discount.created_at = discounts['created_at']
                discount.updated_at = discounts['updated_at']
                count_discount = discount.where({'discount_id': discount.discount_id})
                if len(count_discount) > 0 or discount.deleted_at:
                    for data in count_discount:
                        discount.id = data['id']
                        if discount.deleted_at:
                            discount.delete()
                        else:
                            discount.update_special()
                else:
                    discount.add_special()
            discount.close_connection()

        if 'inventories' in updates:
            for inventories in updates['inventories']:
                inventory = Inventory()
                inventory.inventory_id = inventories['id']
                inventory.company_id = inventories['company_id']
                inventory.name = inventories['name']
                inventory.description = inventories['description']
                inventory.ordered = inventories['ordered']
                inventory.laundry = inventories['laundry']
                inventory.status = inventories['status']
                inventory.deleted_at = inventories['deleted_at']
                inventory.create_at = inventories['created_at']
                inventory.updated_at = inventories['updated_at']
                count_inventory = inventory.where({'inventory_id': inventory.inventory_id})
                if len(count_inventory) > 0 or inventory.deleted_at:
                    for data in count_inventory:
                        inventory.id = data['id']
                        if inventory.deleted_at:
                            inventory.delete()
                        else:
                            inventory.update_special()
                else:
                    inventory.add_special()
            inventory.close_connection()

        if 'inventory_items' in updates:
            for inventory_items in updates['inventory_items']:
                inventory_item = InventoryItem()
                inventory_item.item_id = inventory_items['id']
                inventory_item.inventory_id = inventory_items['inventory_id']
                inventory_item.company_id = inventory_items['company_id']
                inventory_item.name = inventory_items['name']
                inventory_item.description = inventory_items['description']
                inventory_item.tags = inventory_items['tags']
                inventory_item.quantity = inventory_items['quantity']
                inventory_item.ordered = inventory_items['ordered']
                inventory_item.price = inventory_items['price']
                inventory_item.image = inventory_items['image']
                inventory_item.status = inventory_items['status']
                inventory_item.deleted_at = inventory_items['deleted_at']
                inventory_item.created_at = inventory_items['created_at']
                inventory_item.updated_at = inventory_items['updated_at']
                count_inventory_item = inventory_item.where({'item_id': inventory_item.item_id})
                if len(count_inventory_item) > 0 or inventory_item.deleted_at:
                    for data in count_inventory_item:
                        inventory_item.id = data['id']
                        if inventory_item.deleted_at:
                            inventory_item.delete()
                        else:
                            inventory_item.update_special()
                else:
                    inventory_item.add_special()
            inventory_item.close_connection()

        # if 'invoice_items' in updates:
        #     for invoice_items in updates['invoice_items']:
        #         invoice_item = InvoiceItem()
        #         invoice_item.invoice_items_id = invoice_items['id']
        #         invoice_item.invoice_id = invoice_items['invoice_id']
        #         invoice_item.item_id = invoice_items['item_id']
        #         invoice_item.inventory_id = invoice_items['inventory_id']
        #         invoice_item.company_id = invoice_items['company_id']
        #         invoice_item.customer_id = invoice_items['customer_id']
        #         invoice_item.quantity = invoice_items['quantity']
        #         invoice_item.color = invoice_items['color']
        #         invoice_item.memo = invoice_items['memo']
        #         invoice_item.pretax = invoice_items['pretax']
        #         invoice_item.tax = invoice_items['tax']
        #         invoice_item.total = invoice_items['total']
        #         invoice_item.status = invoice_items['status']
        #         invoice_item.deleted_at = invoice_items['deleted_at']
        #         invoice_item.created_at = invoice_items['created_at']
        #         invoice_item.updated_at = invoice_items['updated_at']
        #         count_invoice_item = invoice_item.where({'invoice_items_id': invoice_item.invoice_items_id})
        #         if len(count_invoice_item) > 0 or invoice_item.deleted_at:
        #             for data in count_invoice_item:
        #                 invoice_item.id = data['id']
        #                 if invoice_item.deleted_at:
        #                     invoice_item.delete()
        #                 else:
        #                     invoice_item.update_special()
        #         else:
        #             invoice_item.add_special()
        #     invoice_item.close_connection()
        #
        # if 'invoices' in updates:
        #
        #     for invoices in updates['invoices']:
        #         invoice = Invoice()
        #         invoice.invoice_id = invoices['id']
        #         invoice.company_id = invoices['company_id']
        #         invoice.customer_id = invoices['customer_id']
        #         invoice.quantity = invoices['quantity']
        #         invoice.pretax = invoices['pretax']
        #         invoice.tax = invoices['tax']
        #         invoice.reward_id = invoices['reward_id']
        #         invoice.discount_id = invoices['discount_id']
        #         invoice.total = invoices['total']
        #         invoice.rack = invoices['rack']
        #         invoice.rack_date = invoices['rack_date']
        #         invoice.due_date = invoices['due_date']
        #         invoice.memo = invoices['memo']
        #         invoice.transaction_id = invoices['transaction_id']
        #         invoice.schedule_id = invoices['schedule_id']
        #         invoice.status = invoices['status']
        #         invoice.deleted_at = invoices['deleted_at']
        #         invoice.created_at = invoices['created_at']
        #         invoice.updated_at = invoices['updated_at']
        #
        #         # extra loop through invoice items to delete or check for data
        #         if 'invoice_items' in invoices:
        #
        #             iitems = invoices['invoice_items']
        #             if len(iitems) > 0:
        #                 for iitem in iitems:
        #                     invoice_item = InvoiceItem()
        #                     invoice_item.invoice_items_id = iitem['id']
        #                     invoice_item.invoice_id = iitem['invoice_id']
        #                     invoice_item.item_id = iitem['item_id']
        #                     invoice_item.inventory_id = iitem['inventory_id']
        #                     invoice_item.company_id = iitem['company_id']
        #                     invoice_item.customer_id = iitem['customer_id']
        #                     invoice_item.quantity = iitem['quantity']
        #                     invoice_item.color = iitem['color']
        #                     invoice_item.memo = iitem['memo']
        #                     invoice_item.pretax = iitem['pretax']
        #                     invoice_item.tax = iitem['tax']
        #                     invoice_item.total = iitem['total']
        #                     invoice_item.status = iitem['status']
        #                     invoice_item.deleted_at = iitem['deleted_at']
        #                     invoice_item.created_at = iitem['created_at']
        #                     invoice_item.updated_at = iitem['updated_at']
        #                     count_invoice_item = invoice_item.where({'invoice_items_id': invoice_item.invoice_items_id})
        #                     if len(count_invoice_item) > 0 or invoice_item.deleted_at:
        #                         for data in count_invoice_item:
        #                             invoice_item.id = data['id']
        #                             if invoice_item.deleted_at:
        #                                 invoice_item.delete()
        #                             else:
        #                                 invoice_item.update_special()
        #
        #         count_invoice = invoice.where({'invoice_id': invoice.invoice_id})
        #         if len(count_invoice) > 0 or invoice.deleted_at:
        #             for data in count_invoice:
        #                 invoice.id = data['id']
        #                 if invoice.deleted_at:
        #                     invoice.delete()
        #                 else:
        #                     invoice.update_special()
        #         else:
        #             invoice.add_special()
        #     invoice.close_connection()

        if 'memos' in updates:
            for memos in updates['memos']:
                memo = Memo()
                memo.memo_id = memos['id']
                memo.company_id = memos['company_id']
                memo.memo = memos['memo']
                memo.ordered = memos['ordered']
                memo.status = memos['status']
                memo.deleted_at = memos['deleted_at']
                memo.created_at = memos['created_at']
                memo.updated_at = memos['updated_at']
                count_memo = memo.where({'memo_id': memo.memo_id})
                if len(count_memo) > 0 or memo.deleted_at:
                    for data in count_memo:
                        memo.id = data['id']
                        if memo.deleted_at:
                            memo.delete()
                        else:
                            memo.update_special()
                else:
                    memo.add_special()
            memo.close_connection()

        # if 'printers' in updates:
        #     for printers in updates['printers']:
        #         printer = Printer()
        #         printer.printer_id = printers['id']
        #         printer.company_id = printers['company_id']
        #         printer.name = printers['name']
        #         printer.model = printers['model']
        #         printer.nick_name = printers['nick_name']
        #         printer.type = printers['type']
        #         printer.vendor_id = printers['vendor_id']
        #         printer.product_id = printers['product_id']
        #         printer.status = printers['status']
        #         printer.deleted_at = printers['deleted_at']
        #         printer.created_at = printers['created_at']
        #         printer.updated_at = printers['updated_at']
        #         count_printer = printer.where({'printer_id': printer.printer_id})
        #         if len(count_printer) > 0 or printer.deleted_at:
        #             for data in count_printer:
        #                 printer.id = data['id']
        #                 if printer.deleted_at:
        #                     printer.delete()
        #                 else:
        #                     printer.update_special()
        #         else:
        #             printer.add_special()
        #     printer.close_connection()

        if 'profiles' in updates:
            for profiles in updates['profiles']:
                profile = Profile()
                profile.p_id = profiles['id']
                profile.company_id = profiles['company_id']
                profile.user_id = profiles['user_id']
                profile.profile_id = profiles['profile_id']
                profile.status = profiles['status']
                profile.deleted_at = profiles['deleted_at']
                profile.created_at = profiles['created_at']
                profile.updated_at = profiles['updated_at']
                count_profile = profile.where({'p_id': profile.p_id})
                if len(count_profile) > 0 or profile.deleted_at:
                    for data in count_profile:
                        profile.id = data['id']
                        if profile.deleted_at:
                            profile.delete()
                        else:
                            profile.update_special()
                else:
                    profile.add_special()
            profile.close_connection()


        if 'reward_transactions' in updates:
            for reward_transactions in updates['reward_transactions']:
                reward_transaction = RewardTransaction()
                reward_transaction.reward_id = reward_transactions['reward_id']
                reward_transaction.transaction_id = reward_transactions['transaction_id']
                reward_transaction.customer_id = reward_transactions['customer_id']
                reward_transaction.employee_id = reward_transactions['employee_id']
                reward_transaction.company_id = reward_transactions['company_id']
                reward_transaction.type = reward_transactions['type']
                reward_transaction.points = reward_transactions['points']
                reward_transaction.credited = reward_transactions['credited']
                reward_transaction.reduced = reward_transactions['reduced']
                reward_transaction.running_total = reward_transactions['running_total']
                reward_transaction.reason = reward_transactions['reason']
                reward_transaction.name = reward_transactions['name']
                reward_transaction.status = reward_transactions['status']
                reward_transaction.deleted_at = reward_transactions['deleted_at']
                reward_transaction.created_at = reward_transactions['created_at']
                reward_transaction.updated_at = reward_transactions['updated_at']
                count_reward_transaction = reward_transaction.where({'reward_id': reward_transaction.reward_id})
                if len(count_reward_transaction) > 0 or reward_transaction.deleted_at:
                    for data in count_reward_transaction:
                        reward_transaction.id = data['id']
                        if reward_transaction.deleted_at:
                            reward_transaction.delete()
                        else:
                            reward_transaction.update_special()
                else:
                    reward_transaction.add_special()
            reward_transaction.close_connection()

        if 'rewards' in updates:
            for rewards in updates['rewards']:
                reward = Reward()
                reward.reward_id = rewards['id']
                reward.company_id = rewards['company_id']
                reward.name = rewards['name']
                reward.points = rewards['points']
                reward.discount = rewards['discount']
                reward.status = rewards['status']
                reward.deleted_at = rewards['deleted_at']
                reward.created_at = rewards['created_at']
                reward.updated_at = rewards['updated_at']
                count_reward = reward.where({'reward_id': reward.reward_id})
                if len(count_reward) > 0 or reward.deleted_at:
                    for data in count_reward:
                        reward.id = data['id']
                        if reward.deleted_at:
                            reward.delete()
                        else:
                            reward.update_special()
                else:
                    reward.add_special()
            reward.close_connection()

        if 'schedules' in updates:
            for schedules in updates['schedules']:
                schedule = Schedule()
                schedule.schedule_id = schedules['id']
                schedule.company_id = schedules['company_id']
                schedule.customer_id = schedules['customer_id']
                schedule.card_id = schedules['card_id']
                schedule.pickup_delivery_id = schedules['pickup_delivery_id']
                schedule.pickup_address = schedules['pickup_address']
                schedule.pickup_date = schedules['pickup_date']
                schedule.dropoff_delivery_id = schedules['dropoff_delivery_id']
                schedule.dropoff_address = schedules['dropoff_address']
                schedule.dropoff_date = schedules['dropoff_date']
                schedule.special_instructions = schedules['special_instructions']
                schedule.type = schedules['type']
                schedule.token = schedules['token']
                schedule.status = schedules['status']
                schedule.deleted_at = schedules['deleted_at']
                schedule.created_at = schedules['created_at']
                schedule.updated_at = schedules['updated_at']
                count_schedule = schedule.where({'schedule_id': schedule.schedule_id})
                if len(count_schedule) > 0 or schedule.deleted_at:
                    for data in count_schedule:
                        schedule.id = data['id']
                        if schedule.deleted_at:
                            schedule.delete()
                        else:
                            schedule.update_special()
                else:
                    schedule.add_special()
            schedule.close_connection()

        if 'taxes' in updates:
            for taxes in updates['taxes']:
                tax = Tax()
                tax.tax_id = taxes['id']
                tax.company_id = taxes['company_id']
                tax.rate = taxes['rate']
                tax.status = taxes['status']
                tax.deleted_at = taxes['deleted_at']
                tax.created_at = taxes['created_at']
                tax.updated_at = taxes['updated_at']
                count_tax = tax.where({'tax_id': tax.tax_id})
                if len(count_tax) > 0 or tax.deleted_at:
                    for data in count_tax:
                        tax.id = data['id']
                        if tax.deleted_at:
                            tax.delete()
                        else:
                            tax.update_special()
                else:
                    tax.add_special()
            tax.close_connection()

        if 'transactions' in updates:
            for transactions in updates['transactions']:
                transaction = Transaction()
                transaction.trans_id = transactions['id']
                transaction.company_id = transactions['company_id']
                transaction.customer_id = transactions['customer_id']
                transaction.schedule_id = transactions['schedule_id']
                transaction.pretax = transactions['pretax']
                transaction.tax = transactions['tax']
                transaction.aftertax = transactions['aftertax']
                transaction.credit = transactions['credit']
                transaction.discount = transactions['discount']
                transaction.total = transactions['total']
                transaction.invoices = transactions['invoices'] if transactions['invoices'] else None
                transaction.account_paid = transactions['account_paid']
                transaction.account_paid_on = transactions['account_paid_on']
                transaction.type = transactions['type']
                transaction.last_four = transactions['last_four']
                transaction.tendered = transactions['tendered']
                transaction.transaction_id = transactions['transaction_id']
                transaction.status = transactions['status']
                transaction.deleted_at = transactions['deleted_at']
                transaction.created_at = transactions['created_at']
                transaction.updated_at = transactions['updated_at']
                count_transaction = transaction.where({'trans_id': transaction.trans_id})
                if len(count_transaction) > 0 or transaction.deleted_at:
                    for data in count_transaction:
                        transaction.id = data['id']
                        if transaction.deleted_at:
                            transaction.delete()
                        else:
                            transaction.update_special()
                else:
                    transaction.add_special()
            transaction.close_connection()

        if 'users' in updates:
            for users in updates['users']:
                user = User()
                user.user_id = users['id']
                user.company_id = users['company_id']
                user.username = users['username']
                user.first_name = users['first_name']
                user.last_name = users['last_name']
                user.street = users['street']
                user.suite = users['suite']
                user.city = users['city']
                user.state = users['state']
                user.zipcode = users['zipcode']
                user.email = users['email']
                user.phone = users['phone']
                user.intercom = users['intercom']
                user.concierge_name = users['concierge_name']
                user.concierge_number = users['concierge_number']
                user.special_instructions = users['special_instructions']
                user.shirt_old = users['shirt_old']
                user.shirt = users['shirt']
                user.delivery = users['delivery']
                user.profile_id = users['profile_id']
                user.payment_status = users['payment_status']
                user.payment_id = users['payment_id']
                user.token = users['token']
                user.api_token = users['api_token']
                user.reward_status = users['reward_status']
                user.reward_points = users['reward_points']
                user.account = users['account']
                user.account_total = users['account_total']
                user.credits = users['credits']
                user.starch = users['starch']
                user.important_memo = users['important_memo']
                user.invoice_memo = users['invoice_memo']
                user.role_id = users['role_id']
                user.deleted_at = users['deleted_at']
                user.created_at = users['created_at']
                user.updated_at = users['updated_at']
                count_user = user.where({'user_id': user.user_id})
                if len(count_user) > 0 or user.deleted_at:
                    for data in count_user:
                        user.id = data['id']
                        if user.deleted_at:
                            user.delete()
                        else:
                            user.update_special()
                else:
                    user.add_special()
            user.close_connection()

        if 'zipcodes' in updates:
            for zipcodes in updates['zipcodes']:
                zipcode = Zipcode()
                zipcode.zipcode_id = zipcodes['id']
                zipcode.company_id = zipcodes['company_id']
                zipcode.delivery_id = zipcodes['delivery_id']
                zipcode.zipcode = zipcodes['zipcode']
                zipcode.status = zipcodes['status']
                zipcode.deleted_at = zipcodes['deleted_at']
                zipcode.created_at = zipcodes['created_at']
                zipcode.updated_at = zipcodes['updated_at']
                # check to see if color_id already exists and update
        
                count_zipcode = zipcode.where({'zipcode_id': zipcode.zipcode_id})
                if len(count_zipcode) > 0 or zipcode.deleted_at:
                    for data in count_zipcode:
                        zipcode.id = data['id']
                        if zipcode.deleted_at:
                            zipcode.delete()
                        else:
                            zipcode.update_special()
                else:
                    zipcode.add_special()
            zipcode.close_connection()
import random
from cards import Card

deck = []
suit =''
rank = 0
for suit_id in range(1,5):
    for rank_id in range(1,14):
        new_card = Card(suit, rank)
        if new_card.rank == 8:
            new_card.value = 50        
        deck.append(Card(suit_id,rank_id))

hand = []
for cards in range(0,5):
    a = random.choice(deck)
    hand.append(a)
    deck.remove(a)

print
for card in hand:
    print card.short_name, '=', card.long_name, " Value:", card.value

def player_turn():
    global deck, p_hand, blocked, up_card, active_suit

    
    print"\nYour hand:",
    for card in p_hand:
        print card.short_name,
        print " Up card: ", up_card.short_name
 def setUp(self):
     self.card = Card("Hearts", "A")
Exemple #31
0
def points_in_trick(card1: Card, card2: Card, card3: Card, card4: Card):
    points: int = card1.get_point() + card2.get_point() + card3.get_point(
    ) + card4.get_point()
    return points
def test_finish_fix(cards_db, start_state_fixture):
    i = cards_db.add_card(Card("foo", state=start_state_fixture))
    cards_db.finish(i)
    c = cards_db.get_card(i)
    assert c.state == "done"
def test_count_one_card(cards_db):
    cards_db.add_card(Card("foo"))
    assert cards_db.count() == 1
Exemple #34
0
 def testMakeDeck(self):
     d = Card.makeDeck()
     self.assertEqual(len(d),52,'testCard:testMakeDeck:Deck should have 52 cards')
     self.assertEqual(len(list(filter(lambda c:c.suit=='H',d))),13,'testCard:testMakeDeck:Deck should have 13 cards of hearts suit')
     self.assertEqual(len(list(filter(lambda c:c.rank=='A',d))),4,'testCard:testMakeDeck:Deck should have 4 aces')
Exemple #35
0
 def setUp(self):
     self.card = Card('HQ')
     self.kinds = ['S', 'C', 'D', 'H']
     self.values = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
 def test_finish_from_in_prog(self, cards_db):
     i = cards_db.add_card(Card("foo", state="in prog"))
     cards_db.finish(i)
     c = cards_db.get_card(i)
     assert c.state == "done"
 def test_Card_num_suits(self):
     self.assertEqual(Card.num_suits(), 4)
Exemple #38
0
def test_xfail_strict():
    c1 = Card("a task")
    c2 = Card("a task")
    assert c1 == c2
    def test_Card_check(self):
        c1 = Card(0, 0)
        self.assertEqual(c1, Card.check(c1))

        with self.assertRaises(ValueError):
            Card.check(None)
            Card.check(0)
            Card.check({0, 1})
            Card.check([0, 1])
            Card.check((0, 1))
            Card.check(1.0)
            Card.check("1.0")
Exemple #40
0
class TestCard(unittest.TestCase):
    def setUp(self):
        self.card = Card()
        
        self.connectionsChanged_count = 0
        def connectionsChanged_spy():
            self.connectionsChanged_count += 1
        self.card.connectionsChanged.connect(connectionsChanged_spy)
    
    def test_defaults(self):
        """ The card initially consists of dead ends with no point value """
        for i in range(6):
            self.assertEqual(self.card.connections[i], Card.DEAD_END)
            self.assertEqual(self.card.point_values[i], 0)
    
    def test_constructor_with_endpoint_list(self):
        """ You can pass in a list of endpoint connections to the constructor """
        # arrange
        endpoint_connections = [ [0, 1], [3, 4, 5] ]
        # act
        self.card = Card(endpoint_connections)
        # assert
        self.assertEqual(self.card.getConnectedEndpoints(), endpoint_connections)
    
    def test_connectEndpoints_emits_signal(self):
        """ connectionsChanged signal should be emitted every time connectEndpoints() is called """
        # arrange
        # act
        self.card.connectEndpoints([0])
        # assert
        self.assertEqual(self.connectionsChanged_count, 1)
    
    def test_basic_connectEndpoints_is_symmetric(self):
        """ When a basic straight connection is made, both endpoints point to one another """
        # arrange
        source = 3
        target = 4
        # act
        self.card.connectEndpoints([source, target])
        # assert
        self.assertEqual(self.card.connections[source], [target])
        self.assertEqual(self.card.connections[target], [source])
    
    def test_multiple_connectEndpoints_is_symmetric(self):
        """ When a non-straight connection is made, all involved endpoints point to all other involved endpoints """
        # arrange
        endpoints = [2, 4, 3]
        exp_connections = self.card.connections[:]
        exp_connections[2] = [3, 4]
        exp_connections[3] = [2, 4]
        exp_connections[4] = [2, 3]
        # act
        self.card.connectEndpoints(endpoints)
        # assert
        self.assertEqual(self.card.connections, exp_connections)
    
    def test_flip_emits_signal(self):
        """ connectionsChanged signal should be emitted every time flip() is called """
        # arrange
        # act
        self.card.flip()
        # assert
        self.assertEqual(self.connectionsChanged_count, 1)
    
    def test_flip_maintains_connections(self):
        """ When a card is flipped, connections are maintained correctly """
        # arrange
        self.card.connections = [[4], [5], [3], [2], [0], [1]]
        exp_connections = [[5], [3], [4], [1], [2], [0]]
        # act
        self.card.flip()
        # assert
        self.assertEqual(self.card.connections, exp_connections)
    
    def test_getConnectedEndpoints(self):
        """ getConnectedEndpoints() should return a list of endpoint groupings """
        # arrange
        exp_endpoint_connections = [ [0, 1], [3, 4, 5] ]
        for connection in exp_endpoint_connections:
            self.card.connectEndpoints(connection)
        # act
        endpoint_connections = self.card.getConnectedEndpoints()
        # assert
        self.assertEqual(endpoint_connections, exp_endpoint_connections)
    
    def test_eq_with_non_card_object(self):
        """ Ensure that the equality operator returns false for non-card objects """
        # arrange
        non_card = 3
        # act
        equal = (self.card == non_card)
        # assert
        self.assertFalse(equal)
    
    def test_eq_with_identical_cards(self):
        """ Ensure that cards which are the same evaluate as equal """
        # arrange
        endpoints = [ [0, 1], [2, 5] ]
        self.card = Card(endpoints)
        card2 = Card(endpoints)
        # act
        equal = (self.card == card2)
        # assert
        self.assertTrue(equal)
    
    def test_ne_with_non_card_object(self):
        """ Ensure that the inequality operator returns true for non-card objects """
        # arrange
        non_card = 3
        # act
        not_equal = (self.card != non_card)
        # assert
        self.assertTrue(not_equal)
    
    def test_ne_with_identical_cards(self):
        """ Ensure that cards which are the same evaluate as equal """
        # arrange
        endpoints = [ [0, 1], [2, 5] ]
        self.card = Card(endpoints)
        card2 = Card(endpoints)
        # act
        not_equal = (self.card != card2)
        # assert
        self.assertFalse(not_equal)
Exemple #41
0
	def _set_CARTA(self, val):
		self.card = Card.parse(val)
Exemple #42
0
 def __init__(self, suit, rank, isCovered = False):
     Card.__init__(self, suit, rank)
     self.isCovered = isCovered
Exemple #43
0
def update_database(data):
    print('updating db')
    # start upload text
    if int(data['rows_saved']) > 0:
        if 'saved' in data:
            saved = data['saved']
            if 'addresses' in saved:
                for addresses in saved['addresses']:
                    address = Address()
                    where = {'id': addresses['id']}
                    data = {'address_id': addresses['address_id']}
                    address.put(where=where, data=data)

            if 'colors' in saved:
                for colors in saved['colors']:
                    color = Colored()
                    where = {'id': colors['id']}
                    data = {'color_id': colors['color_id']}
                    color.put(where=where, data=data)
                    
            if 'cards' in saved:
                for cards in saved['cards']:
                    card = Card()
                    where = {'id': cards['id']}
                    data = {'card_id': cards['card_id']}
                    card.put(where=where, data=data)
            if 'credits' in saved:
                for credit in saved['credits']:
                    credits = Credit()
                    where = {'id': credit['id']}
                    data = {'credit_id': credit['credit_id']}
                    credits.put(where=where, data=data)
            if 'companies' in saved:
                for companies in saved['companies']:
                    company = Company()
                    where = {'id': companies['id']}
                    data = {'company_id': companies['company_id']}
                    company.put(where=where, data=data)

            if 'custids' in saved:
                for custids in saved['custids']:
                    custid = Custid()
                    where = {'id': custids['id']}
                    data = {'cust_id': custids['cust_id']}
                    custid.put(where=where, data=data)

            if 'deliveries' in saved:
                for deliveries in saved['deliveries']:
                    delivery = Delivery()
                    where = {'id': deliveries['id']}
                    data = {'delivery_id': deliveries['delivery_id']}
                    delivery.put(where=where, data=data)

            if 'discounts' in saved:
                for discounts in saved['discounts']:
                    discount = Discount()
                    where = {'id': discounts['id']}
                    data = {'discount_id': discounts['discount_id']}
                    discount.put(where=where, data=data)

            if 'inventories' in saved:
                for inventories in saved['inventories']:
                    inventory = Inventory()
                    where = {'id': inventories['id']}
                    data = {'inventory_id': inventories['inventory_id']}
                    inventory.put(where=where, data=data)

            if 'inventory_items' in saved:
                for inventory_items in saved['inventory_items']:
                    inventory_item = InventoryItem()
                    where = {'id': inventory_items['id']}
                    data = {'item_id': inventory_items['item_id']}
                    inventory_item.put(where=where, data=data)

            if 'invoices' in saved:
                for invoices in saved['invoices']:

                    invoice = Invoice()
                    where = {'id': invoices['id']}
                    data = {'invoice_id': invoices['invoice_id']}
                    invoice.put(where=where, data=data)

            if 'invoice_items' in saved:
                for invoice_items in saved['invoice_items']:

                    invoice_item = InvoiceItem()
                    where = {'id': invoice_items['id']}
                    data = {'invoice_items_id': invoice_items['invoice_items_id']}
                    invoice_item.put(where=where, data=data)

            if 'memos' in saved:
                for memos in saved['memos']:
                    memo = Memo()
                    where = {'id': memos['id']}
                    data = {'memo_id': memos['memo_id']}
                    memo.put(where=where, data=data)
            if 'printers' in saved:
                for printers in saved['printers']:
                    printer = Printer()
                    where = {'id': printers['id']}
                    data = {'printer_id': printers['printer_id']}
                    printer.put(where=where, data=data)
                    
            if 'profiles' in saved:
                for profiles in saved['profiles']:
                    profile = Profile()
                    where = {'id': profiles['id']}
                    data = {'p_id': profiles['p_id']}
                    profile.put(where=where, data=data)
                    
            if 'reward_transactions' in saved:
                for reward_transactions in saved['reward_transactions']:
                    reward_transaction = RewardTransaction()
                    where = {'id': reward_transactions['id']}
                    data = {'reward_id': reward_transactions['reward_id']}
                    reward_transaction.put(where=where, data=data)

            if 'rewards' in saved:
                for rewards in saved['rewards']:
                    reward = Reward()
                    where = {'id': rewards['id']}
                    data = {'reward_id': rewards['reward_id']}
                    reward.put(where=where, data=data)

            if 'schedules' in saved:
                for schedules in saved['schedules']:
                    schedule = Schedule()
                    where = {'id': schedules['id']}
                    data = {'schedule_id': schedules['schedule_id']}
                    schedule.put(where=where, data=data)

            if 'taxes' in saved:
                for taxes in saved['taxes']:
                    tax = Tax()
                    where = {'id': taxes['id']}
                    data = {'tax_id': taxes['tax_id']}
                    tax.put(where=where, data=data)

            if 'transactions' in saved:
                for transactions in saved['transactions']:
                    transaction = Transaction()
                    where = {'id': transactions['id']}
                    data = {'trans_id': transactions['trans_id']}
                    transaction.put(where=where, data=data)

            if 'users' in saved:
                for users in saved['users']:
                    user = User()
                    where = {'id': users['id']}
                    data = {'user_id': users['user_id']}
                    user.put(where=where, data=data)

            if 'zipcodes' in saved:
                for zipcodes in saved['zipcodes']:
                    zipcode = Zipcode()
                    where = {'id': zipcodes['id']}
                    data = {'zipcode_id': zipcodes['zipcode_id']}
                    zipcode.put(where=where, data=data)
Exemple #44
0
# -*- coding: UTF-8 -*-
# 建立一副牌
import random
from cards import Card

deck = []
for suit_id in range(1, 5):
    for rank_id in range(1, 14):
        deck.append(Card(suit_id, rank_id))

hand = []
for cards in range(0, 5):
    a = random.choice(deck)
    hand.append(a)
    deck.remove(a)

print
for card in hand:
    print card.short_name, '=', card.long_name, "  Value:", card.value