Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
This is a script I used to repair our marketplace after corrupting it with multiple valid cards/bank accounts per account. See
#!/usr/bin/env python
import sys
sys.path.insert(0, 'env/lib/python2.7/site-packages') # kludge for running
# under foreman
import balanced
import gittip
from gittip import wireup
participants = gittip.db.fetchall("""
SELECT balanced_account_uri
FROM participants
WHERE balanced_account_uri IS NOT NULL
for participant in participants:
account = balanced.Account.find(participant['balanced_account_uri'])
for thing_type in ('card', 'bank_account'):
things = getattr(account, thing_type+'s').all()
things = [thing for thing in things if thing.is_valid]
nvalid = len(things)
if nvalid > 1:
things.sort(key=lambda x: x.created_at)
print nvalid, account.uri
print " *" + str(things[-1].created_at)
for thing in things[:-1]:
print " ", thing.created_at
thing.is_valid = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.