Skip to content

Instantly share code, notes, and snippets.

@dreamingbinary
Created February 22, 2017 08:14
Show Gist options
  • Save dreamingbinary/9904705f8606ccd3b063b30f404c35d6 to your computer and use it in GitHub Desktop.
Save dreamingbinary/9904705f8606ccd3b063b30f404c35d6 to your computer and use it in GitHub Desktop.
Jorge's Stripe Analytics File
import os
import string
import json
R=[]
ii=0
data_id='#######################'
found=0
while ii<2000:
if ii>=0:
modstart='-d starting_after='+str(data_id)+''
else:
modstart=''
print modstart
curl_string = 'curl https://api.stripe.com/v1/charges?limit=100 -H "Authorization: Bearer ############################" '+str(modstart)+' -d expand[]=data.customer -G'
print curl_string
r1 = os.popen(curl_string).read()
r2=string.replace(r1,"\n ","")
r3=string.replace(r2," ","")
r4=json.loads(r3)
print len(r4['data'])
w=len(r4['data'])
#print r4
r5=[]
i=0
while i<w:
print r4['data'][i]['id']
status=r4['data'][i]['status'] #charge status*
card_customer=r4['data'][i]['card']['customer'] #customer id
created=r4['data'][i]['created'] #unix ts
data_id=r4['data'][i]['id'] #charge id
#print 'here1'
failure_code=r4['data'][i]['failure_code'] #failure code
if r4['data'][i]['outcome']==None:
pass
outcome_network_status='na'
outcome_reason='na'
else:
outcome_network_status=r4['data'][i]['outcome']['network_status'] #DBN *
outcome_reason=r4['data'][i]['outcome']['reason'] #2nd cat reason
cardId=r4['data'][i]['card']['id'] #Card Id *
cardType=r4['data'][i]['card']['brand'] #Card Type
cardFunding=r4['data'][i]['card']['funding'] #debit
amount=r4['data'][i]['amount']# amount
customer_OBJECT=r4['data'][i]['customer']
if 'deleted' in customer_OBJECT:
pass
customer_created='999'
customer_email='999'
else:
customer_created=r4['data'][i]['customer']['created']
customer_email=r4['data'][i]['customer']['email']
#plan=r4['data'][i]['subscriptions']['data']['plan']['id']
#plan_interval=r4['data'][i]['subscriptions']['data']['plan']['id']
#plan_interval=r4['data'][i]['subscriptions']['data']['plan']['id']
#print status
row=[status,card_customer,created,data_id,failure_code,outcome_network_status,outcome_reason,cardId,cardType,cardFunding,amount,customer_created ,customer_email]#,plan,plan_interval]
r5.append(row)
print 'i: '+str(i)
i+=1
R.extend(r5)
print 'ii: '+str(ii)
ii+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment