Created
March 20, 2013 11:04
-
-
Save chadwhitacre/5203859 to your computer and use it in GitHub Desktop.
This is a script I used to repair our marketplace after corrupting it with multiple valid cards/bank accounts per account. See https://github.com/gittip/www.gittip.com/issues/773.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
wireup.db() | |
wireup.billing() | |
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 | |
thing.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment