def add(self, type_, amount, appData):
     appData['total'] -= amount
     if appData[type_] > 0:
         appData[type_] += amount
     else:
         appData[type_] = 0
         appData[type_] += amount
     printWait("Your total balance now is Rs." + str(appData['total']))
 def withdraw(self, amount, appData):
     if (amount > appData['total']):
         print("Sorry, you do not have enough money!")
     else:
         appData['total'] -= amount
         print("Withdrawing...")
         progressBar(endText="Withdrawal Succesful!")
         printWait("Your total balance now is Rs." + str(appData['total']))
Esempio n. 3
0
def progressBar(marker="#", length=15, endText="Done!"):
    bar = "[]"
    progress = ""
    for i in range(length):
        progress += marker
        print(bar[0] + progress + " " * (length - 1 - i) + bar[1],
              flush=True,
              end="\r")
        time.sleep(0.1)
    printWait(endText.center(length + 2), end="\n", flush=True)
 def create(self, name, amount, appData):
     types = appData['types'].split('/')
     types.append(name)
     appData['types'] = "/".join(types)
     if (amount > appData['total']):
         print(
             "Sorry, you do not have enough money to spend on this thing!")
     else:
         appData['total'] -= amount
         appData[name] = amount
         printWait("Your total balance now is Rs." + str(appData['total']))
 def remove(self, type_, amount, appData):
     if (amount > appData[type_]):
         print("Sorry, that's not possible!")
     elif (amount == appData[type_]):
         types.remove(type_)
         appData['types'] = "/".join(types)
     else:
         appData['total'] += amount
         appData[type_] -= amount
         print("Tranferring Rs." + str(amount) +
               " back to your Total Balance...")
         progressBar(endText="Transfer Complete!")
         printWait("Your total balance now is Rs." + str(appData['total']))
def checkOrCreateData(name, password):
    # Create shelve object while keeping nomenclature
    # to the specific user for easier access
    appData = shelve.open(('fad' + name))
    printWait("\nInitializing your account...")
    printWait("Retrieving any previous data, if any...")
    # Checking username against existing shelve data
    if (name in appData):
        progressBar(endText="Data found. Checking password...")
        # If username exists, then check password
        # against user-defined existing shelve data
        while (password != appData['password']):
            password = str(input("Wrong password. Try again!\nPassword: "******"Password is correct! Logging in...")
        progressBar(endText="Success!")
        # Save the specific shelve object to a variable for
        # permanent data accessibility for the user session
        user = appData[name]
    else:
        progressBar(endText="No previous record found.")
        if (confirm("\nWould you like to create a new account?") == True):
            # Creating new user object using data provided
            # by user at script initialization
            user = Budget(name, password)
            # Saving customized class object to shelve object
            appData[user.user_name] = user
            printWait("Creating account...")
            progressBar(endText="Account created.")
        else:
            printWait("I will not create an account. Exiting program...")
            # Deleting data that this script may have unintentionally
            # created while checking for username against shelve data
            try:
                os.unlink(os.path.abspath(os.curdir) + "fad" + name + ".dir")
                pritn("Deleted .dir")
                os.unlink(os.path.abspath(os.curdir) + "fad" + name + ".bak")
                print("Deleted .bak")
                os.unlink(os.path.abspath(os.curdir) + "fad" + name + ".dat")
                print("Deleted .dat")
            except FileNotFoundError:
                print("Couldn't delete file.")
            quit()
    return user, appData
 def deposit(self, amount, appData):
     if amount > 0:
         appData['total'] += amount
         print("Depositing...")
         progressBar(endText="Deposit Succesful!")
         printWait("Your total balance now is Rs." + str(appData['total']))