def create_card_holds(self, cursor):

        # Get the list of participants to create card holds for
        participants = cursor.all("""
            SELECT *
              FROM payday_participants
             WHERE old_balance < giving_today
               AND has_credit_card
               AND is_suspicious IS false
        """)
        if not participants:
            return {}

        # Fetch existing holds
        participant_ids = set(p.id for p in participants)
        holds = self.fetch_card_holds(participant_ids)

        # Create new holds and check amounts of existing ones
        def f(p):
            amount = p.giving_today - p.old_balance

            if p.id in holds:
                if amount >= MINIMUM_CHARGE:
                    charge_amount = upcharge(amount)[0]
                    if holds[p.id].amount >= charge_amount:
                        return
                    else:
                        # The amount is too low, cancel the hold and make a new one
                        cancel_card_hold(holds.pop(p.id))
                else:
                    # not up to minimum charge level. cancel the hold
                    cancel_card_hold(holds.pop(p.id))
                    return
            if amount >= MINIMUM_CHARGE:
                hold, error = create_card_hold(self.db, p, amount)
                if error:
                    return 1
                else:
                    holds[p.id] = hold
        threaded_map(f, participants)

        # Update the values of card_hold_ok in our temporary table
        if not holds:
            return {}
        cursor.run("""
            UPDATE payday_participants p
               SET card_hold_ok = true
             WHERE p.id IN %s
        """, (tuple(holds.keys()),))

        return holds
dataset/ETHPy150Open gratipay/gratipay.com/gratipay/billing/payday.py/Payday.create_card_holds/original