Last active
December 22, 2015 20:58
-
-
Save nickpersico/6529642 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| ###### Invoices Out This Week | |
| week_inv_url = 'https://app.close.io/api/v1/activity/status_change/opportunity/?date_created__gt=%s&date_created__lt=%s' % (rightmonday, upcomingsunday) | |
| week_inv_created_url = 'https://app.close.io/api/v1/opportunity/?status_id=%s&date_created__gt=%s&date_created__lt=%s' % (invoice_status, rightmonday, upcomingsunday) | |
| week_inv = 0 | |
| week_inv_created = 0 | |
| week_inv_value = 0 | |
| week_inv_value_c = 0 | |
| has_more = True | |
| offset = 0 | |
| week_inv_ids = [] | |
| week_inv_id = [] | |
| while has_more: | |
| week_inv_created_resp = requests.get(week_inv_created_url, auth=(api_key, ''), params={'_skip': offset, '_limit': 100}, headers={'Content-Type': 'application/json'}) | |
| week_inv_created_data = week_inv_created_resp.json['data'] | |
| for opportunity in week_inv_created_data: | |
| if opportunity['status_id'] == '%s' % invoice_status: | |
| week_inv_ids.append([opportunity['id']]) | |
| week_inv_created = week_inv_created + 1 | |
| week_inv_value_c += opportunity['value']/100.0 | |
| offset += len(week_inv_created_data) | |
| has_more = week_inv_created_resp.json['has_more'] | |
| has_more = True | |
| offset = 0 | |
| while has_more: | |
| week_inv_resp = requests.get(week_inv_url, auth=(api_key, ''), params={'_skip': offset, '_limit': 100}, headers={'Content-Type': 'application/json'}) | |
| week_inv_data = week_inv_resp.json['data'] | |
| for invoice in week_inv_data: | |
| if invoice['new_status_id'] == '%s' % invoice_status: | |
| for opp in week_inv_ids: | |
| if invoice['opportunity_id'] in opp: | |
| week_inv = week_inv - 1 | |
| value = invoice['opportunity_value_formatted'][1:] | |
| clean_value = value.replace(',', '') | |
| week_inv_value -= Decimal(clean_value) | |
| else: | |
| week_inv = week_inv + 1 | |
| value = invoice['opportunity_value_formatted'][1:] | |
| clean_value = value.replace(',', '') | |
| week_inv_value += Decimal(clean_value) | |
| offset += len(week_inv_data) | |
| has_more = week_inv_resp.json['has_more'] | |
| print week_inv + week_inv_created | |
| print week_inv_value_c + float(week_inv_value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment