Exemple #1
0
def main():
    with app.app_context():
        db.metadata.create_all(db.engine)

        create_more = 'y'
        while create_more == 'y':
            print 'Enter firstname: ',
            firstname = raw_input()

            print 'Enter lastname: ',
            lastname = raw_input()

            print 'Enter email: ',
            email = raw_input()

            print 'Enter password',
            password = raw_input()

            print 'Enter balance: ',
            balance = raw_input()

            print 'Enter group: ',
            group = raw_input()

            print 'Enter isGroupOwner (y/n): ',
            is_group_owner = True if raw_input() == 'y' else False

            print 'Enter isAdmin (y/n): ',
            is_admin = True if raw_input() == 'y' else False

            print 'Enter Saturday absent weeks: ',
            saturday_absent_weeks = raw_input()

            future_saturday_absent_weeks = 0
            if int(saturday_absent_weeks) <= 0:
                print 'Enter future Saturday absent weeks: ',
                future_saturday_absent_weeks = raw_input()

            print 'Enter Sunday absent weeks: ',
            sunday_absent_weeks = raw_input()

            future_sunday_absent_weeks = 0
            if int(sunday_absent_weeks) <= 0:
                print 'Enter future Sunday absent weeks: ',
                future_sunday_absent_weeks = raw_input()

            user = User(firstname, lastname, email, password, balance, group,
                        is_group_owner, is_admin, saturday_absent_weeks,
                        future_saturday_absent_weeks, sunday_absent_weeks,
                        future_sunday_absent_weeks)
            db.session.add(user)
            db.session.commit()

            print 'Do you want to create more users (y/n): ',
            create_more = raw_input()
def main():
    with app.app_context():
        """Get all users whose balance is less than or equal $10"""
        users = User.query.filter(User.balance <= 10)

        for user in users:
            subject = 'Badminton: Your balance is low please top up'
            message = 'Hi ' + user.firstname + \
                      ',\r\n\nYour balance is currently running low and it is ' + str(user.balance) + \
                      '$. Please top up your account.\r\n\nThanks\r\nSydney Badminton Group'
            SendGrid.send_email(user.email, "*****@*****.**", subject,
                                message)
Exemple #3
0
def main():
    with app.app_context():
        db.metadata.create_all(db.engine)

        createMore = 'y'
        while (createMore == 'y'):
            print 'Enter cost: ',
            cost = raw_input()

            print 'Enter day: ',
            day = raw_input()

            courtsCost = CourtsCost(cost, day)
            db.session.add(courtsCost)
            db.session.commit()

            print 'Do you want to create more users (y/n): ',
            createMore = raw_input()
Exemple #4
0
def main():
    with app.app_context():
        users = User.query.order_by(User.firstname.asc()).all()

        for user in users:
            forgot_password_token = uuid.uuid1()
            user.forgotPasswordToken = str(forgot_password_token)
            db.session.commit()

            subject = "Badminton: set password to access your account"
            message = 'Hi ' + user.firstname + ",\r\n\n" + \
                      'In order to access your account on new Badminton website you need to click the below link' + \
                      ' to set your password.\r\n\n' + \
                      'http://' + app.config['HOST_NAME'] + "/resetPassword?token=" + user.forgotPasswordToken + \
                      '\r\n\nPlease bookmark following URL for easy access to the website in future.\r\n\n' + \
                      'http://' + app.config['HOST_NAME'] + \
                      '\r\n\nThanks\r\n Maddy'
            SendGrid.send_email(user.email, "*****@*****.**", subject, message)
            print 'Sent an email to: ' + user.firstname
def main():
    with app.app_context():
        db.metadata.create_all(db.engine)

        createMore = 'y'
        while (createMore == 'y'):
            print 'Enter email: ',
            email = raw_input()

            print 'Enter amount: ',
            amount = raw_input()

            print 'Enter balance: ',
            balance = raw_input()

            print 'Enter type: ',
            type = raw_input()

            transaction = Transaction(email, amount, balance, type)
            db.session.add(transaction)
            db.session.commit()

            print 'Do you want to create more users (y/n): ',
            createMore = raw_input()
def main():
    with app.app_context():
        db.metadata.create_all(db.engine)
        """User table"""
        with open('_User.json') as user_data_file:
            user_data = json.load(user_data_file)
        users = user_data["results"]
        for user in users:
            print 'Firstname = ' + user["firstname"]
            print 'Lastname = ' + user["lastname"]
            user_row = User(user["firstname"], user["lastname"], user["username"],
                            user["bcryptPassword"], user["balance"], user["group"],
                            bool(user["isGroupOwner"]), bool(user["isAdmin"]),
                            user["saturdayAbsentWeeks"], user["futureSaturdayAbsentWeeks"],
                            user["sundayAbsentWeeks"], user["futureSundayAbsentWeeks"],
                            parser.parse(user["createdAt"]), parser.parse(user["updatedAt"]))
            db.session.add(user_row)
            db.session.commit()

        """CourtsCost table"""
        with open('CourtsCost.json') as courts_cost_data_file:
            courts_cost_data = json.load(courts_cost_data_file)
        courts_costs = courts_cost_data["results"]
        for courts_cost in courts_costs:
            courts_cost_row = CourtsCost(courts_cost["cost"], courts_cost["day"],
                                         parser.parse(courts_cost["createdAt"]),
                                         parser.parse(courts_cost["updatedAt"]))
            db.session.add(courts_cost_row)
            db.session.commit()

        """Expenses table"""
        with open("Expenses.json") as expenses_data_file:
            expenses_data = json.load(expenses_data_file)
        expenses = expenses_data["results"]
        for expense in expenses:
            expense_row = Expense(expense["cost"], expense["costPerPerson"],
                                  expense["description"], expense["numberOfPlayers"],
                                  parser.parse(expense["createdAt"]),
                                  parser.parse(expense["updatedAt"]))
            db.session.add(expense_row)
            db.session.commit()

        """Transactions table"""
        with open("Transactions_Table.json") as transactions_data_file:
            transactions_data = json.load(transactions_data_file)
        transactions = transactions_data["results"]
        for transaction in transactions:
            transaction_row = Transaction(transaction["username"], transaction["Amount"],
                                          transaction["Total_Amount"], transaction["Transaction_Type"],
                                          parser.parse(transaction["Date"]["iso"]),
                                          parser.parse(transaction["createdAt"]),
                                          parser.parse(transaction["updatedAt"]))
            db.session.add(transaction_row)
            db.session.commit()

        """Logs table"""
        with open('Logs.json') as data_file:
            data = json.load(data_file)
        logs = data['results']
        for log in logs:
            log_row = Log(log["username"], log["description"], parser.parse(log["createdAt"]),
                          parser.parse(log["updatedAt"]))
            db.session.add(log_row)
            db.session.commit()
Exemple #7
0
def run_expense(day):
    with app.app_context():
        if day != "Saturday" and day != "Sunday":
            return

        courts_cost = CourtsCost.query.filter_by(day=day).first()

        if day == "Saturday":
            players = User.query.filter_by(isSaturdayAbsent=False).order_by(User.firstname.asc())
            absent_players = User.query.filter_by(isSaturdayAbsent=True).order_by(User.firstname.asc())
        elif day == "Sunday":
            players = User.query.filter_by(isSundayAbsent=False).order_by(User.firstname.asc())
            absent_players = User.query.filter_by(isSundayAbsent=True).order_by(User.firstname.asc())
        db.session.close()

        email_ids = []
        body_text = ""
        if players.count() > 0:
            cost_per_player = float("{0:.2f}".format(float(courts_cost.cost) / float(players.count())))

            """Add expense entry"""
            expence_description = ("Deduction_Sunday", "Deduction_Saturday")[day == "Saturday"]
            expenseEntry = Expense(courts_cost.cost, cost_per_player, expence_description, players.count())
            db.session.add(expenseEntry)
            db.session.commit()

            body_text += 'Hi everyone,\r\n\nA total of ' + str(players.count()) + ' players attended the play on ' \
                        + day + ' and courts booking cost = $' + str(courts_cost.cost) + '. So cost per player = $' + \
                        str(cost_per_player) + ".\r\n\nBalances of played players are as follows:\r\n\n"

            for player in players:
                player.balance = float("{0:.2f}".format(player.balance - cost_per_player))

                transaction = Transaction(player.email, cost_per_player, player.balance,
                                          ("Deduct_Sun", "Deduct_Sat")[day == "Saturday"])
                db.session.add(transaction)
                db.session.commit()

                email_ids.append(player.email);
                body_text += player.firstname + ' ' + player.lastname + ' : ' + '$' + str(player.balance) + '\r\n'

        body_text += '\nBalances of absent players are as follows\r\n\n'

        for absent_player in absent_players:
            if day == "Saturday":
                absent_player.saturdayAbsentWeeks -= 1
                if absent_player.saturdayAbsentWeeks <= 0:
                    absent_player.saturdayAbsentWeeks = 0
                    absent_player.isSaturdayAbsent = False
            elif day == "Sunday":
                absent_player.sundayAbsentWeeks -= 1
                if absent_player.sundayAbsentWeeks <= 0:
                    absent_player.sundayAbsentWeeks = 0
                    absent_player.isSundayAbsent = False
            db.session.commit()

            email_ids.append(absent_player.email)
            body_text += absent_player.firstname + ' ' + absent_player.lastname + ' : ' + '$' + str(absent_player.balance) + '\r\n'

        """Check if user is absent in future, if so set the absent weeks, absent flag
            and set future absent weeks to zero"""
        for player in players:
            future_absent_weeks = (player.futureSundayAbsentWeeks,
                                   player.futureSaturdayAbsentWeeks)[day == "Saturday"]
            if future_absent_weeks > 0:
                if day == "Saturday":
                    player.futureSaturdayAbsentWeeks = 0
                    player.isSaturdayAbsent = True
                    player.saturdayAbsentWeeks = future_absent_weeks
                elif day == "Sunday":
                    player.futureSundayAbsentWeeks = 0
                    player.isSundayAbsent = True
                    player.sundayAbsentWeeks = future_absent_weeks
            db.session.commit()

        body_text += '\nThanks\r\nSydney Badminton Group'
        # SendGrid.send_email(email_ids, "*****@*****.**",
        #                     "Badminton: Balances after " + day + "'s play", body_text)

        return