Bump to 0.8.24
[theonering] / hand_tests / gv_load_csv.py
1 #!/usr/bin/env python
2
3 from __future__ import with_statement
4 from __future__ import division
5
6 import sys
7 sys.path.insert(0,"../src")
8
9 import csv
10 import logging
11
12 try:
13         import cStringIO as StringIO
14 except ImportError:
15         import StringIO
16
17 import gvoice.backend as backend
18
19
20 _moduleLogger = logging.getLogger(__name__)
21
22
23 if __name__ == "__main__":
24         logging.basicConfig(level=logging.DEBUG)
25
26         args = sys.argv
27
28         if True:
29                 username = args[1]
30                 password = args[2]
31                 b = backend.GVoiceBackend()
32                 b.login(username, password)
33                 data = b.get_csv_contacts()
34                 with open("test.csv", "wb") as f:
35                         f.write(data)
36         else:
37                 with open("test.csv", "U") as f:
38                         data = f.read()
39         if True:
40                 if False:
41                         # used with the official gmail one returned by passing no export params
42                         data = "".join(c for (i, c) in enumerate(data) if (i%2 == 0))[1:]
43                 for attr in csv.DictReader(StringIO.StringIO(data)):
44                         for name in attr.keys():
45                                 if not attr[name] or name is None:
46                                         del attr[name]
47                         #print attr
48                         if any(attr[name] for name in attr.keys() if "Phone" in name):
49                                 print attr