Skip to content

Instantly share code, notes, and snippets.

@chadwhitacre
Created July 27, 2012 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadwhitacre/3190978 to your computer and use it in GitHub Desktop.
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
#!/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