Ejemplo n.º 1
0
def menu():
    connection = database.connect()
    database.create_tables(connection)

    while (user_input := input(MENU_PROMPT)) != "0":
        if user_input == "1":
            card_number = generate_card_number()
            pin = generate_pin()

            database.add_card(connection, card_number, pin)

            print("Your card has been created")
            print(f"Your card number:\n{card_number}")
            print(f"Your card PIN:\n{pin}")
        elif user_input == "2":
            card_number = input("Enter your card number:\n")
            entered_pin = input("Enter your PIN:\n")
            if database.get_pin_by_number(connection, card_number) == entered_pin:
                print("You have successfully logged in!")

                while True:
                    user_input = input(LOGGED_IN_MENU_PROMPT)
                    if user_input == "1":
                        print(f"Balance: {database.get_balance_by_number(connection, card_number)}")
                    elif user_input == "2":
                        income = input("Enter income:\n")
                        database.add_income(connection, income, card_number)
                        print("Income was added!")
                    elif user_input == "3":
                        print("Transfer")
                        recipient = input("Enter card number: ")
                        if recipient != card_number:
                            if check_luhn(recipient):
                                x = database.get_card_by_number(connection, recipient)
                                if x is not None:
                                    payment = int(input("Enter how much money you want to transfer:\n"))
                                    if payment <= database.get_balance_by_number(connection, card_number):
                                        database.add_forfeit(connection, payment, card_number)
                                        database.add_income(connection, payment, recipient)
                                        print("Success!")
                                    else:
                                        print("Not enough money!")
                                else:
                                    print("Such a card does not exist.")
                            else:
                                print("Probably you made a mistake in the card number. Please try again!")
                        else:
                            print("You can't transfer money to the same account!")
                    elif user_input == "4":
                        database.delete_by_number(connection, card_number)
                        print("The account has been closed!")
                        break
                    elif user_input == "5":
                        print("You have successfully logged out!")
                        break
                    elif user_input == "0":
                        print("Bye!")
                        exit()
            else:
                print("Wrong card number or PIN!")
Ejemplo n.º 2
0
def create_account(connection):
    """Create new account and show info about it to the user"""

    card_number = generate_card_num(connection)
    pin = generate_pin()

    # Adding new card to database
    database.add_card(connection, card_number, pin)

    print("\nYour card has been created\n"
          "Your card number:\n"
          f"{card_number}\n"
          "Your card PIN:\n"
          f"{pin}\n")
Ejemplo n.º 3
0
 def do(self):
     super().do()
     if int(self.sender.id) != 223212153207783435:
         return f"{self.sender.mention} isn't allowed to do that :D"
     if len(self.args) == 1:
         card_id = int(self.args[0])
         if database.add_card(self.sender, card_id):
             return f"Transaction completed: you added {database.get_card_by_id(card_id)} to your cards"
         else:
             return "forgot to do !start"
     else:
         return f"command {self.name} has too many or too little arguments ( {self.args})"
Ejemplo n.º 4
0
def menu():
    print()
    while 1:
        print("Actions with cards:")
        print("   1.Add card")
        print("   2.Delete card")
        print("   3.Import money")
        print("   4.Withdraw money")
        print("Actions with categories:")
        print("   5.Create category")
        print("   6.Delete category")
        print("   7.Show all categories")
        print("Information:")
        print("   8.Check balance")
        print("   9.Show chart of imports and withdraws by month")
        print("   10.Show chart of withdraws by category")
        print("   11.Show all withdraws")
        print("      11.1 Show withdraws by card")
        print("      11.2 Show withdraws by category")
        print("      11.3 Show withdraws by date (today)")
        print("      11.4 Show withdraws by month")
        print("   12.Show transfers")
        print("   13.Show all imports")
        print("      13.1 Show imports by card")
        print("      13.2 Show imports by date (today)")
        print("      13.3 Show imports by month")
        print("Actions with history:")
        print("   14.Delete all")
        print("      14.1 Delete by card")
        print("      14.2 Delete by category")
        print("Transfers")
        print("   15.Transfer between cards")
        print("")

        choice = input("Please make a choice: ")
        print()
        if choice == "15":
            db = TinyDB("DB.json")
            cards = db.table('cards')
            if len(cards.all()) > 1:
                display = dbs.display_cards()
                if display != 1:
                    print()
                    op1 = int(input('Choose a card to withdraw from: '))
                    op2 = int(input('Choose a card to insert in: '))
                    if op1 != op2:
                        money = float(input('Amount of money you wanna insert: '))
                        dbs.transfer(op1, op2, money)
                    else:
                        print("You must have 2 or more cards to make this operation")
            else:
                print("You have only one card!")
            del cards
            del db
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "14.2":
            display = dbs.display_categories()
            if display != 1:
                print()
                op = int(input('Choose category: '))
                dbs.delete_history_category(op)
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "14.1":
            display = dbs.display_cards()
            if display != 1:
                print()
                op = int(input('Choose card: '))
                dbs.delete_history_card(op)
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "14":
            op = input('Are you sure you want to delete all history?')
            if op == 'Y' or op == 'y':
                dbs.delete_history()
            else:
                print("Action canceled")
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "13.3":
            month = int(input("Enter number of a month you want to check (1 to 12)"))
            if month <= 12:
                dbs.search_by_month(month, "import")
            else:
                print("Enter number between 1 and 12")
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "13.2":
            dbs. operations_today("import")
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "13.1":
            display = dbs.display_cards()
            if display != 1:
                print()
                op = int(input('Choose card: '))
                dbs.show_imports_card(op)
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "13":
            dbs.show_imports()
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "12":
            dbs.show_transfers()
            print()
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "11.3":
            dbs.operations_today("withdraw")
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "11.4":
            month = int(input("Enter number of a month you want to check (1 to 12)"))
            if month <= 12:
                dbs.search_by_month(month, "withdraw")
            else:
                print("Enter number between 1 and 12")
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "11.2":
            display = dbs.display_categories()
            if display != 1:
                print()
                op = int(input('Choose category: '))
                dbs.show_withdraws_category(op)
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "11.1":
            display = dbs.display_cards()
            if display != 1:
                print()
                op = int(input('Choose card: '))
                dbs.show_withdraws_card(op)
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "11":
            dbs.show_withdraws()
            print()
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "10":
            dbs.chart_operation_category()
            print()
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "9":
            month = int(input("Enter number of a month you want to check (1 to 12)"))
            if month <= 12:
                dbs.chart_operation_month(month)
            else:
                print("Enter number between 1 and 12")
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "8":
            display = dbs.display_cards()
            if display != 1:
                print()
                op = int(input('Choose card: '))
                dbs.balance(op)
            dbs.total_balance()
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "7":
            dbs.display_categories()
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "6":
            display = dbs.display_categories()
            if display != 1:
                print()
                op = int(input('Choose category: '))
                dbs.delete_category(op)
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "5":
            name = input("Write category: ")
            dbs.create_category(name)
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "4":
            display = dbs.display_cards()
            if display != 1:
                print()
                op = int(input('Choose card: '))
                money = float(input('Amount of money you wanna withdraw: '))
                dbs.display_categories()
                op_category = int(input("Choose category"))
                op_description = input("Add description (optional): ")
                dbs.withdraw_money(op,money,op_category,op_description)
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "3":
            display = dbs.display_cards()
            if display != 1:
                print()
                op = int(input('Choose card: '))
                money = float(input('Amount of money you wanna insert: '))
                dbs.import_money(op,money)
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "2":
            dbs.delete_card()
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        elif choice == "1":
            dbs.add_card()
            op = input('Wanna continue?: ')
            if op == 'N' or op == 'n':
                break
        else:
            print("EXIT")
            break
    return 0
Ejemplo n.º 5
0
    def do(self):
        super().do()
        embed = discord.Embed(descrption="Auctions", color=discord.Color.red())
        embed.set_author(name=self.sender.name, icon_url=self.client.user.avatar_url)

        page = 0
        if len(self.args) == 1:
            try:
                page = int(self.args[0])
            except ValueError:
                return f"{self.args[0]} is not a valid number"
        if len(self.args) == 0:
            # change the values so they work in discord.py
            auctions = database.all_auctions(page)
            print(auctions)
            if len(auctions) == 0:
                return "No auctions"
            cleaned_results = [f"{r[0]} :: {util.escape_underscore(r[1])} :: " 
                               f"{r[2]} :: {database.get_card_by_id(r[3])[2]}"
                               for r in auctions]
            embed.add_field(name="Auctions(id::owner::money::card)", value="\n".join(cleaned_results), inline=False)
            embed.set_footer(
                text=f"Showing page {page + 1} of {int(database.count_all_auctions() / 10) + 1}")
            return None, embed
        if self.args[0] == "accept" and self.args[1]:
            try:
                auction_id = int(self.args[1])
                if not database.check_auction(auction_id):
                    return f"{self.args[1]} is not a valid auction id!"
            except ValueError:
                return f"{self.args[1]} is not a valid auction id!"
            # here:
            auction = database.get_auction(auction_id)[0]
            print(auction)
            if database.get_balance(self.sender) >= auction[2]:
                database.remove_auction(auction[0])
                database.add_card(self.sender, auction[3])
                database.add_balance(self.sender, -auction[2])
                database.add_balance_id(auction[4], auction[2])
                return f"You earned {database.get_card_by_id(auction[3])[2]} " \
                       f"from an auction with a bid of {auction[2]}"
            else:
                return "You do not have enough money to accept that auction!"
        elif self.args[0] == "revoke" and self.args[1]:
            try:
                auction_id = int(self.args[1])
                if not database.check_auction(auction_id):
                    return f"{self.args[1]} is not a valid auction id!"
            except ValueError:
                return f"{self.args[1]} is not a valid auction id!"
            auction = database.get_auction(auction_id)[0]
            database.remove_auction(auction[0])
            database.add_card(self.sender, auction[3])
            return f"You revoked auction {auction_id}"
        elif len(self.args) == 2:
            try:
                bid_balance = int(self.args[1])
                card_id = database.get_card(self.args[0])
            except ValueError:
                return f"{self.args[1]} is not a valid number"
            if card_id is not None:
                if card_id in database.get_cards(self.sender):
                    full_card = database.get_card_by_id(card_id)
                    database.add_auction(self.sender, card_id, bid_balance)
                    c = database.remove_card(self.sender, card_id)
                    print(c)
                    if c:
                        return f"You put {full_card[2]} up for auction for {bid_balance} money"
                    else:
                        print("Error in auctioning card")
                else:
                    return f"You do not have that card!"
            else:
                return f"Invalid card"
Ejemplo n.º 6
0
    @staticmethod
    def luhn_check(number):
        return True if Card.__luhn_sum(number) % 10 == 0 else False


conn = database.connect()
database.create_table(conn)
loop = 1
while loop == 1:
    print(MENU_LOGIN)
    choice = input()
    print()
    if choice == '1':
        new_card = Card()
        database.add_card(conn, new_card.card_number, new_card.pin)
        print("Your card has been created")
        print("Your card number:")
        print(new_card.card_number)
        print("Your card PIN:")
        print(new_card.pin)
    elif choice == '2':
        print("Enter your card number:")
        user_card_number = input()
        print("Enter your PIN")
        user_pin = input()
        if not database.check_card_pin(conn, user_card_number, user_pin):
            print("Wrong card number or PIN!")
            continue
        print("You have successfully logged in!")
        while True: