|
6 | 6 | import json |
7 | 7 | from os.path import join, dirname |
8 | 8 | from watson_developer_cloud import PersonalityInsightsV3 |
| 9 | +import csv |
9 | 10 |
|
10 | 11 | # # If service instance provides API key authentication |
11 | 12 | # service = PersonalityInsightsV3( |
12 | | -# version='2016-10-20', |
| 13 | +# version='2017-10-13', |
13 | 14 | # ## url is optional, and defaults to the URL below. Use the correct URL for your region. |
14 | 15 | # url='https://gateway.watsonplatform.net/personality-insights/api', |
15 | 16 | # iam_apikey='your_apikey') |
16 | 17 |
|
17 | 18 | service = PersonalityInsightsV3( |
18 | | - version='2016-10-20', |
| 19 | + version='2017-10-13', |
19 | 20 | ## url is optional, and defaults to the URL below. Use the correct URL for your region. |
20 | 21 | # url='https://gateway.watsonplatform.net/personality-insights/api', |
21 | 22 | username='YOUR SERVICE USERNAME', |
22 | 23 | password='YOUR SERVICE PASSWORD') |
23 | 24 |
|
| 25 | +############################ |
| 26 | +# Profile with JSON output # |
| 27 | +############################ |
| 28 | + |
24 | 29 | with open(join(dirname(__file__), '../resources/personality-v3.json')) as \ |
25 | 30 | profile_json: |
26 | 31 | profile = service.profile( |
|
30 | 35 | consumption_preferences=True).get_result() |
31 | 36 |
|
32 | 37 | print(json.dumps(profile, indent=2)) |
| 38 | + |
| 39 | +########################### |
| 40 | +# Profile with CSV output # |
| 41 | +########################### |
| 42 | + |
| 43 | +with open(join(dirname(__file__), '../resources/personality-v3.json')) as \ |
| 44 | + profile_json: |
| 45 | + response = service.profile( |
| 46 | + profile_json.read(), |
| 47 | + content_type='application/json', |
| 48 | + accept="text/csv", |
| 49 | + csv_headers=True).get_result() |
| 50 | + |
| 51 | +profile = response.content |
| 52 | +cr = csv.reader(profile.splitlines()) |
| 53 | +my_list = list(cr) |
| 54 | +for row in my_list: |
| 55 | + print(row) |
0 commit comments