示例#1
0
def test_get_card(db_empty):
    c = Card(summary="something", owner="okken")
    id = cards.add_card(c)

    retrieved_card = cards.get_card(id)

    assert retrieved_card == c
    assert retrieved_card.id == id
示例#2
0
def test_update(db_non_empty):
    # GIVEN a card known to be in the db
    all_cards = cards.list_cards()
    a_card = all_cards[0]

    # WHEN we update() the card with new info
    cards.update_card(a_card.id, Card(owner="okken", done=True))

    # THEN we can retrieve the card with get() and
    # and it has all of our changes
    updated_card = cards.get_card(a_card.id)
    expected = Card(summary=a_card.summary, owner="okken", done=True)
    assert updated_card == expected
示例#3
0
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
import atexit
import os
import shutil
import string
import sys
import re
import tempfile
import cards

card = sys.argv[1]
card = cards.get_card(card)
pinvhdl = sys.argv[2]
cardvhdl = card.name + "card"

_sq_whitelist = string.lowercase + string.uppercase + string.digits + ".-_/"


def sq(a):
    if not a.strip(_sq_whitelist):
        return a
    return "'" + a.replace("'", "'\\''") + "'"


def run(*args):
    print >> sys.stderr, "#", " ".join([sq(a) for a in args])
    r = os.spawnvp(os.P_WAIT, args[0], args)
示例#4
0
    input, continue asking.
    """

    while True:
        user_input = input("Do you want to (h)it or (s)tand? ").lower()
        if user_input in ("h", "s"):
            return user_input

        print("I don't understand that input. Try again.")


if __name__ == "__main__":
    deck = cards.create_deck(shuffle=True)
    hand = []

    hand.append(cards.get_card(deck))
    hand.append(cards.get_card(deck))

    bust = cards.calculate_hand_score(hand) > 21
    stand = False

    while not bust and not stand:
        print_hand(hand)
        hit_or_stand = ask_user_to_hit_or_stand()
        if hit_or_stand == "h":
            hand.append(cards.get_card(deck))
            bust = cards.calculate_hand_score(hand) > 21
        else:
            stand = True

    print_hand(hand)
示例#5
0
def cmd_fetch(message):
    global last_card
    response = ''
    pattern = re.compile("<<([^<>]*)>>")
    queries = pattern.findall(message.content)

    for s in queries:
        query = s
        proc = subprocess.Popen(['mtg', query, '--json'], stdout=subprocess.PIPE)
        result = str(proc.communicate()[0].decode('utf-8'))

        card_list = json.loads(result)

        # Store the card if it's the only one
        last_card = None
        if len(card_list) == 1:
            if len(queries) == 1:
                last_card = card_list[0]
            response += '\n' + cards.get_card(message, card_list[0]) + '\n'
            continue

        # If no cards are found, we are done
        if len(card_list) == 0:
            response += '\n**' + query + '**: *The ritual summoned nothing but ash...*\n'
            continue

        # If an exact card is found, just print that one
        # When you find the exact match, break out of the for card in cards loop
        # Then "continue" the for s in queries to move to the next query
        # If you find an exact match and there is only 1 query in the buffer,
        # Get the details and rulings of the exact card, as they are skipped when mtg cli returns multiple
        done = False
        for card in card_list:
            if (card['name'].lower() == query.lower()):     # If name matches query
                DFC=False                                                   # Assume it's not a DFC
                if len(card_list) == 2:                                     # If exactly 2 cards are found
                    if 'card_number' in card:                               # If the Card HAS a card number
                        DFC=True                                            #   It must be a DFC
                        if 'a' in card['card_number']:                      #   Get the correct side of the DFC
                            if len(queries) == 1:
                                last_card = card_list[0]
                            response += cards.get_card(message, card_list[0])
                            response += cards.get_card(message, card_list[1])
                        elif 'b' in card['card_number']:
                            if len(queries) == 1:
                                last_card = card_list[1]
                            response += cards.get_card(message, card_list[0])
                            response += cards.get_card(message, card_list[1])
                    else:                                                   # If it turns out to NOT be a DFC
                        DFC=False                                           #   Send it through the normal logic
                if not DFC:
                    response += cards.get_card(message, card)
                    if len(queries) == 1:                                   # Send a new query with --exact
                        newProcess = subprocess.Popen(['mtg', query, '--json', '--exact'], stdout=subprocess.PIPE)
                        newResult = str(newProcess.communicate()[0].decode('utf-8'))
                        newList = json.loads(newResult)
                        if len(newList) > 0:
                            last_card = newList[0]
                done = True
                break
        if done:
            continue

        # If more than 8 cards are found, don't spam chat
        if len(card_list) > 8:
            response += '\nThe incantations are too long; read them yourself\n'
            continue

        # Finally, if we've gotten to here, print all the cards
        for card in card_list:
            response += '\n' + cards.get_card(message, card) + '\n'

    return response
示例#6
0
def cmd_fetch(message):
    global last_card
    response = ''
    queries = re.findall(("<<([^<>]*)>>"), message.content.encode('utf-8'))

    for s in queries:
        query = s.encode('utf-8')
        proc = subprocess.Popen(['mtg', query, '--json'], stdout=subprocess.PIPE)
        result = str(proc.communicate()[0])

        card_list = json.loads(result)

        # Store the card if it's the only one
        last_card = None
        if len(card_list) == 1:
            if len(queries) == 1:
                last_card = card_list[0]
            response += cards.get_card(message, card_list[0])
            continue

        # If no cards are found, we are done
        if len(card_list) == 0:
            response += '**' + query + '**: *The ritual summoned nothing but ash...*'
            continue

        # If an exact card is found, just print that one
        # When you find the exact match, break out of the for card in cards loop
        # Then "continue" the for s in queries to move to the next query
        # If you find an exact match and there is only 1 query in the buffer, 
        # Get the details and rulings of the exact card, as they are skipped when mtg cli returns multiple
        done = False
        for card in card_list:
            if (card['name'].encode('utf-8').lower() == query.lower()):
                if len(card_list) == 2:
                    if 'a' in card['card_number']:
                        if len(queries) == 1:
                            last_card = card_list[0]
                        response += cards.get_card(message, card_list[0])
                        response += cards.get_card(message, card_list[1])
                    elif 'b' in card['card_number']:
                        if len(queries) == 1:
                            last_card = card_list[1]
                        response += cards.get_card(message, card_list[0])
                        response += cards.get_card(message, card_list[1])
                    else:
                        response += cards.get_card(message, card)
                else:
                    response += cards.get_card(message, card)
                    if len(queries) == 1:
                        newProcess = subprocess.Popen(['mtg', query, '--json', '--exact'], stdout=subprocess.PIPE)
                        newResult = str(newProcess.communicate()[0])
                        newList = json.loads(newResult)
                        if len(newList) > 0:
                            last_card = newList[0]
                done = True
                break
        if done:
            continue

        # If more than 8 cards are found, don't spam chat
        if len(card_list) > 8:
            response += 'The incantations are too long; read them yourself'
            continue

        # Finally, if we've gotten to here, print all the cards
        for card in card_list:
            response += cards.get_card(message, card)

    return response
示例#7
0
def usage(hint='', card=''):
    usage =  __doc__ % sys.argv[0] + help_cards() + help_pins(card)
    if hint: usage += "\n" + hint
    raise SystemExit, usage


def mkdir(a):
    if not os.path.isdir(a): os.mkdir(a)

if len(sys.argv) != 3 and len(sys.argv) != 4:
    usage("Wrong # arguments")
    usage()

card, pin = sys.argv[1:3]
try:
    card = cards.get_card(card)
except KeyError:
    usage("Unknown card %r" % card)

use_ise(card.iseversions)

if not os.path.exists("src/PIN_" + pin + ".vhd"):
    usage("Unknown pin configuration %r" % pin, card)

orgdir = os.getcwd()
if len(sys.argv) == 4:
    outfile = os.path.join(orgdir, sys.argv[3])
else:
    outfile = os.path.join(orgdir, "%s_%s.BIT"% (card.card, pin))

def main():
    display_title()
    money = float(input("Starting money: "))
    while money <= 0:
        print("You must start with more than 0!")
        print()
        money = float(input("Starting money: "))
    print()
    play_again = "y"
    while money > 0 and play_again == "y":
        bet_amount = float(input("Bet amount: "))
        while bet_amount <= 0:
            print("Bet amount must be more than 0!")
            print()
            bet_amount = float(input("Bet amount: "))
        while bet_amount > money:
            print("Sorry, you only have ", money)
            print()
            bet_amount = float(input("Bet amount: "))
        print()
        dealer_hand = []
        player_hand = []
        deck = cards.get_deck()
        random.shuffle(deck)
        dealer_hand.append(cards.get_card(deck))
        dealer_hand.append(cards.get_card(deck))
        player_hand.append(cards.get_card(deck))
        player_hand.append(cards.get_card(deck))
        print("Dealer Hand:")
        show_cards(dealer_hand, True)
        print()
        print("Player Hand:")
        show_cards(player_hand, False)
        print()
        hit_or_stand = input("Hit or stand? (hit/stand): ")
        print()
        while hit_or_stand == "hit":
            player_hand.append(cards.get_card(deck))
            print("Player hand:")
            show_cards(player_hand, False)
            print()
            if cards.get_score(player_hand) > 21:
                print("Sorry, your hand is over 21.")
                print()
                break
            hit_or_stand = input("Hit or stand? (hit/stand): ")
            print()
        while cards.get_score(dealer_hand) < 17:
            dealer_hand.append(cards.get_card(deck))
        print("Dealer's hand:")
        show_cards(dealer_hand, False)
        print()
        dealer_score = cards.get_score(dealer_hand)
        player_score = cards.get_score(player_hand)
        print("YOUR POINTS:      ", player_score)
        print("DEALER'S POINTS:  ", dealer_score)
        print()
        result = play_hand(dealer_score, player_score)
        if result.lower() == "blackjack":
            print("Wow! You got a blackjack!")
            money += bet_amount * 1.5
            money = round(money, 2)
        elif result.lower() == "win":
            print("Hooray! You win!")
            money += bet_amount
        elif result.lower() == "push":
            print("You pushed.")
        elif result.lower() == "lose":
            print("Sorry, you lost.")
            money -= bet_amount
        print("Money: ", money)
        print()
        if money > 0:
            play_again = input("Play again? (y/n): ")
            print()

    print("Bye!")
示例#9
0
def cmd_fetch(message):
    global last_card
    response = ""
    queries = re.findall(("<<([^<>]*)>>"), message.content.encode("utf-8"))

    for s in queries:
        query = s.encode("utf-8")
        proc = subprocess.Popen(["mtg", query, "--json"], stdout=subprocess.PIPE)
        result = str(proc.communicate()[0])

        card_list = json.loads(result)

        # Store the card if it's the only one
        last_card = None
        if len(card_list) == 1:
            if len(queries) == 1:
                last_card = card_list[0]
            response += "\n" + cards.get_card(message, card_list[0]) + "\n"
            continue

        # If no cards are found, we are done
        if len(card_list) == 0:
            response += "\n**" + query + "**: *The ritual summoned nothing but ash...*\n"
            continue

        # If an exact card is found, just print that one
        # When you find the exact match, break out of the for card in cards loop
        # Then "continue" the for s in queries to move to the next query
        # If you find an exact match and there is only 1 query in the buffer,
        # Get the details and rulings of the exact card, as they are skipped when mtg cli returns multiple
        done = False
        for card in card_list:
            if card["name"].encode("utf-8").lower() == query.lower():  # If name matches query
                DFC = False  # Assume it's not a DFC
                if len(card_list) == 2:  # If exactly 2 cards are found
                    if "card_number" in card:  # If the Card HAS a card number
                        DFC = True  #   It must be a DFC
                        if "a" in card["card_number"]:  #   Get the correct side of the DFC
                            if len(queries) == 1:
                                last_card = card_list[0]
                            response += cards.get_card(message, card_list[0])
                            response += cards.get_card(message, card_list[1])
                        elif "b" in card["card_number"]:
                            if len(queries) == 1:
                                last_card = card_list[1]
                            response += cards.get_card(message, card_list[0])
                            response += cards.get_card(message, card_list[1])
                    else:  # If it turns out to NOT be a DFC
                        DFC = False  #   Send it through the normal logic
                if not DFC:
                    response += cards.get_card(message, card)
                    if len(queries) == 1:  # Send a new query with --exact
                        newProcess = subprocess.Popen(["mtg", query, "--json", "--exact"], stdout=subprocess.PIPE)
                        newResult = str(newProcess.communicate()[0])
                        newList = json.loads(newResult)
                        if len(newList) > 0:
                            last_card = newList[0]
                done = True
                break
        if done:
            continue

        # If more than 8 cards are found, don't spam chat
        if len(card_list) > 8:
            response += "\nThe incantations are too long; read them yourself\n"
            continue

        # Finally, if we've gotten to here, print all the cards
        for card in card_list:
            response += "\n" + cards.get_card(message, card) + "\n"

    return response