This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite post-back to circumvent HTTP
- Loading branch information
1 parent
cb93f1c
commit f812fef
Showing
1 changed file
with
12 additions
and
16 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,20 @@ | ||
#!/usr/bin/env python -u | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import csv, os, requests | ||
|
||
gratipay_base_url = 'https://gratipay.com' | ||
gratipay_base_url = 'http://localhost:8537' | ||
gratipay_api_key = os.environ['GRATIPAY_API_KEY'] | ||
import csv | ||
from gratipay import wireup | ||
from gratipay.models.exchange_route import ExchangeRoute | ||
from gratipay.models.participant import Participant | ||
from gratipay.billing.exchanges import record_exchange | ||
|
||
db = wireup.db(wireup.env()) | ||
inp = csv.reader(open('refunds.completed.csv')) | ||
note = 'refund of advance payment; see https://medium.com/gratipay-blog/charging-in-arrears-18cacf779bee' | ||
|
||
for ts, id, amount, username, route_id, status_code, content in inp: | ||
if status_code != '200': continue | ||
url = '{}/~{}/history/record-an-exchange'.format(gratipay_base_url, username) | ||
note = 'refund of advance payment; see https://medium.com/gratipay-blog/charging-in-arrears-18cacf779bee' | ||
|
||
data = { 'amount': amount[:-2] + '.' + amount[-2:] | ||
, 'fee': 0 | ||
, 'note': note | ||
, 'status': 'pending' | ||
, 'route_id': route_id | ||
} | ||
response = requests.post(url, auth=(gratipay_api_key, ''), data=data) | ||
print(response.status_code, response.content) | ||
route = ExchangeRoute.from_id(route_id) | ||
rp = route.participant | ||
participant = Participant.from_id(rp) if type(rp) is long else rp # Such a hack. :( | ||
route.set_attributes(participant=participant) | ||
record_exchange(db, route, -int(amount), 0, participant, 'pending', note) |