Skip to content

Commit 50fca61

Browse files
committed
Handle invalid/unknown Type field
1 parent 7ab977f commit 50fca61

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: duckduckgo.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class Results(object):
5656
def __init__(self, json):
5757
self.type = {'A': 'answer', 'D': 'disambiguation',
5858
'C': 'category', 'N': 'name',
59-
'E': 'exclusive', '': 'nothing'}[json.get('Type','')]
59+
'E': 'exclusive', '': 'nothing'}.get(json.get('Type',''), '')
6060

6161
self.json = json
6262
self.api_version = None # compat
@@ -171,9 +171,9 @@ def main():
171171
keys.sort()
172172
for key in keys:
173173
sys.stdout.write(key)
174-
if type(q.json[key]) in [str,unicode]: print ':', q.json[key]
174+
if type(q.json[key]) in [str,unicode]: print(':', q.json[key])
175175
else:
176176
sys.stdout.write('\n')
177-
for i in q.json[key]: print '\t',i
177+
for i in q.json[key]: print('\t',i)
178178
else:
179-
print 'Usage: %s [query]' % sys.argv[0]
179+
print('Usage: %s [query]' % sys.argv[0])

0 commit comments

Comments
 (0)