-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistcust.py
executable file
·100 lines (64 loc) · 1.93 KB
/
listcust.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/bin/env python
''' listcust -- list hackerspaces QBO customers.
Usage:
listcust [options]
Dump a simple scan of the QBO customers, in CSV.
Options:
--debug Print debugging output. [default: False]
'''
from docopt import docopt
import requests
import json
import hackerspace_utils as hu
import qbo_utils as qu
from quickbooks import Oauth2SessionManager
from quickbooks import QuickBooks
from quickbooks.objects.customer import Customer
from quickbooks.objects import Account
qbo_client = None
session_manager = None
def cust_iterable():
bitesize = 100
reps=0
yielded = 0
while (True):
customers = Customer.filter(Active=True,
qb=qbo_client,
max_results=bitesize,
start_position=yielded+1)
reps += 1
if len(customers) == 0:
return
for item in customers:
yielded += 1
yield(item)
def main():
global session_manager
global qbo_client
authbag = hu.get_auth_bag()
session_manager = Oauth2SessionManager(
client_id=authbag['realm'],
client_secret=authbag['secret'],
access_token=authbag['token'],
refresh_token=authbag['refresh_token'],
base_url=authbag['redirect'],
)
qbo_client = QuickBooks(
# sandbox=True,
session_manager=session_manager,
company_id=authbag['realm']
)
for customer in cust_iterable():
cd = customer.to_dict()
try:
cd['email'] = cd['PrimaryEmailAddr']['Address']
except TypeError:
cd['email'] = ""
print("{Id},{DisplayName},{email}".format(**cd))
if __name__ == '__main__':
arguments = docopt(__doc__, version='Naval Fate 2.0')
debug = arguments['--debug']
if (debug):
print(arguments)
hu.debug=True
main()