|
7 | 7 | __version__ = '0.0.1' |
8 | 8 | __description__ = 'scripting simulator' |
9 | 9 |
|
| 10 | + |
10 | 11 | def json_hash(str): |
11 | | - if str: |
12 | | - return json.loads(str) |
| 12 | + if str: |
| 13 | + return json.loads(str) |
13 | 14 |
|
14 | 15 | # analytics -method=<method> -segment-write-key=<segmentWriteKey> [options] |
15 | 16 |
|
| 17 | + |
16 | 18 | parser = argparse.ArgumentParser(description='send a segment message') |
17 | 19 |
|
18 | 20 | parser.add_argument('--writeKey', help='the Segment writeKey') |
19 | 21 | parser.add_argument('--type', help='The Segment message type') |
20 | 22 |
|
21 | 23 | parser.add_argument('--userId', help='the user id to send the event as') |
22 | | -parser.add_argument('--anonymousId', help='the anonymous user id to send the event as') |
23 | | -parser.add_argument('--context', help='additional context for the event (JSON-encoded)') |
| 24 | +parser.add_argument( |
| 25 | + '--anonymousId', help='the anonymous user id to send the event as') |
| 26 | +parser.add_argument( |
| 27 | + '--context', help='additional context for the event (JSON-encoded)') |
24 | 28 |
|
25 | 29 | parser.add_argument('--event', help='the event name to send with the event') |
26 | | -parser.add_argument('--properties', help='the event properties to send (JSON-encoded)') |
| 30 | +parser.add_argument( |
| 31 | + '--properties', help='the event properties to send (JSON-encoded)') |
27 | 32 |
|
28 | | -parser.add_argument('--name', help='name of the screen or page to send with the message') |
| 33 | +parser.add_argument( |
| 34 | + '--name', help='name of the screen or page to send with the message') |
29 | 35 |
|
30 | | -parser.add_argument('--traits', help='the identify/group traits to send (JSON-encoded)') |
| 36 | +parser.add_argument( |
| 37 | + '--traits', help='the identify/group traits to send (JSON-encoded)') |
31 | 38 |
|
32 | 39 | parser.add_argument('--groupId', help='the group id') |
33 | 40 |
|
34 | 41 | options = parser.parse_args() |
35 | 42 |
|
| 43 | + |
36 | 44 | def failed(status, msg): |
37 | 45 | raise Exception(msg) |
38 | 46 |
|
| 47 | + |
39 | 48 | def track(): |
40 | | - analytics.track(options.userId, options.event, anonymous_id = options.anonymousId, |
41 | | - properties = json_hash(options.properties), context = json_hash(options.context)) |
| 49 | + analytics.track(options.userId, options.event, anonymous_id=options.anonymousId, |
| 50 | + properties=json_hash(options.properties), context=json_hash(options.context)) |
| 51 | + |
42 | 52 |
|
43 | 53 | def page(): |
44 | | - analytics.page(options.userId, name = options.name, anonymous_id = options.anonymousId, |
45 | | - properties = json_hash(options.properties), context = json_hash(options.context)) |
| 54 | + analytics.page(options.userId, name=options.name, anonymous_id=options.anonymousId, |
| 55 | + properties=json_hash(options.properties), context=json_hash(options.context)) |
| 56 | + |
46 | 57 |
|
47 | 58 | def screen(): |
48 | | - analytics.screen(options.userId, name = options.name, anonymous_id = options.anonymousId, |
49 | | - properties = json_hash(options.properties), context = json_hash(options.context)) |
| 59 | + analytics.screen(options.userId, name=options.name, anonymous_id=options.anonymousId, |
| 60 | + properties=json_hash(options.properties), context=json_hash(options.context)) |
| 61 | + |
50 | 62 |
|
51 | 63 | def identify(): |
52 | | - analytics.identify(options.userId, anonymous_id = options.anonymousId, |
53 | | - traits = json_hash(options.traits), context = json_hash(options.context)) |
| 64 | + analytics.identify(options.userId, anonymous_id=options.anonymousId, |
| 65 | + traits=json_hash(options.traits), context=json_hash(options.context)) |
| 66 | + |
54 | 67 |
|
55 | 68 | def group(): |
56 | 69 | analytics.group(options.userId, options.groupId, json_hash(options.traits), |
57 | | - json_hash(options.context), anonymous_id = options.anonymousId) |
| 70 | + json_hash(options.context), anonymous_id=options.anonymousId) |
| 71 | + |
58 | 72 |
|
59 | 73 | def unknown(): |
60 | 74 | print() |
61 | 75 |
|
| 76 | + |
62 | 77 | analytics.write_key = options.writeKey |
63 | 78 | analytics.on_error = failed |
64 | 79 | analytics.debug = True |
|
0 commit comments