Created
July 27, 2012 23:14
-
-
Save chadwhitacre/3190978 to your computer and use it in GitHub Desktop.
This is the script I used to repair Gittip.com issue #202 for $0.50 people
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 datetime | |
from gittip import wireup | |
db = wireup.db() | |
names = open('affected-less.txt') | |
affected = [] | |
for line in names: | |
line = line.strip() | |
if not line: | |
continue | |
if 'gittip-' in line: | |
year, month, day = [int(x) for x in line.split()[0].split('-')] | |
payday = datetime.date(year, month, day) | |
after = datetime.date(year, month, day+1) | |
affected.append((payday, after, [])) | |
elif affected: | |
affected[-1][-1].append(line) | |
for payday, after, names in affected: | |
for name in names: | |
recs = db.fetchall("select participant_id, amount, fee, timestamp " | |
"from exchanges " | |
"where participant_id=%s " | |
"and timestamp > %s " | |
"and timestamp < %s " | |
"order by amount desc", (name, payday, after)) | |
recs = list(recs) | |
assert len(recs) == 1 | |
wrong_amount = recs[0]['amount'] | |
print name.ljust(16), wrong_amount | |
db.execute("update exchanges set amount = 0.18, fee = 0.32 " | |
"where participant_id=%s " | |
"and timestamp > %s and timestamp < %s", | |
(name, payday, after)) | |
db.execute("update participants set balance = balance + (0.18 - %s) " | |
"where id=%s", (wrong_amount, name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment