def process_single_user(username, password):
    try:
        lingo = duolingo.Duolingo(username, password)
    except ValueError:
        raise Exception("Username Invalid")

    print("Trying to Buy Streak Freeze for " + username)
    if(lingo.buy_streak_freeze()):
        print("Bought streak freeze for " + username)
    else:
        print("Unable to buy streak freeze")

    try:
        print("Trying to Buy Double or nothing for " + username)
        lingo.buy_item('rupee_wager', 'en')
        print("Bought Double or nothing for " + username)
    except:
        print("Unable to buy double or nothing")



def main(a, b):
    import duolingo, os

    usernames = os.environ['usernames'].split(',')
    passwords = os.environ['passwords'].split(',')

    list(map(process_single_user, usernames, passwords))

def process_single_user(username, password):
    import duolingo
    try:
        lingo = duolingo.Duolingo(username, password)
    except ValueError:
        raise Exception("Username Invalid")

    stuff_to_purchase = ['streak_freeze', 'rupee_wager']

    for item in stuff_to_purchase:
        try:
            print("Trying to Buy " + item + " for " + username)
            lingo.buy_item(item, 'en')
            print("Bought " + item + " for " + username)
        except duolingo.AlreadyHaveStoreItemException:
            print("Item Already Equipped")
        except Exception:
            raise ValueError("Unable to buy double or nothing")



def main(a, b):
    import duolingo, os

    usernames = os.environ['usernames'].split(',')
    passwords = os.environ['passwords'].split(',')

    list(map(process_single_user, usernames, passwords))

UPdate to duolingo for the API
UPdate to duolingo for the API

  def process_single_user(username, password):
+     import duolingo
      try:
          lingo = duolingo.Duolingo(username, password)
      except ValueError:
          raise Exception("Username Invalid")
  
+     stuff_to_purchase = ['streak_freeze', 'rupee_wager']
-     print("Trying to Buy Streak Freeze for " + username)
-     if(lingo.buy_streak_freeze()):
-         print("Bought streak freeze for " + username)
-     else:
-         print("Unable to buy streak freeze")
  
+     for item in stuff_to_purchase:
-     try:
+         try:
-         print("Trying to Buy Double or nothing for " + username)
+             print("Trying to Buy " + item + " for " + username)
-         lingo.buy_item('rupee_wager', 'en')
+             lingo.buy_item(item, 'en')
-         print("Bought Double or nothing for " + username)
-     except:
+             print("Bought " + item + " for " + username)
+         except duolingo.AlreadyHaveStoreItemException:
+             print("Item Already Equipped")
+         except Exception:
-         print("Unable to buy double or nothing")
+             raise ValueError("Unable to buy double or nothing")
  
  
  
  def main(a, b):
      import duolingo, os
  
      usernames = os.environ['usernames'].split(',')
      passwords = os.environ['passwords'].split(',')
  
      list(map(process_single_user, usernames, passwords))
  
UPdate to duolingo for the API
## Code Before:
def process_single_user(username, password):
    try:
        lingo = duolingo.Duolingo(username, password)
    except ValueError:
        raise Exception("Username Invalid")

    print("Trying to Buy Streak Freeze for " + username)
    if(lingo.buy_streak_freeze()):
        print("Bought streak freeze for " + username)
    else:
        print("Unable to buy streak freeze")

    try:
        print("Trying to Buy Double or nothing for " + username)
        lingo.buy_item('rupee_wager', 'en')
        print("Bought Double or nothing for " + username)
    except:
        print("Unable to buy double or nothing")



def main(a, b):
    import duolingo, os

    usernames = os.environ['usernames'].split(',')
    passwords = os.environ['passwords'].split(',')

    list(map(process_single_user, usernames, passwords))

## Instruction:
UPdate to duolingo for the API
## Code After:
def process_single_user(username, password):
    import duolingo
    try:
        lingo = duolingo.Duolingo(username, password)
    except ValueError:
        raise Exception("Username Invalid")

    stuff_to_purchase = ['streak_freeze', 'rupee_wager']

    for item in stuff_to_purchase:
        try:
            print("Trying to Buy " + item + " for " + username)
            lingo.buy_item(item, 'en')
            print("Bought " + item + " for " + username)
        except duolingo.AlreadyHaveStoreItemException:
            print("Item Already Equipped")
        except Exception:
            raise ValueError("Unable to buy double or nothing")



def main(a, b):
    import duolingo, os

    usernames = os.environ['usernames'].split(',')
    passwords = os.environ['passwords'].split(',')

    list(map(process_single_user, usernames, passwords))
