Skip to content

Commit 72ebd58

Browse files
authored
Update duckduckgo_it.py
1 parent 3a6341d commit 72ebd58

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

APIScripts/DuckDuckGo it/duckduckgo_it.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
"""
2-
This module will take an input string and print the search result.
3-
"""
4-
import requests
5-
1+
import requests # This module will help extract data
62

73
def main():
84

@@ -11,26 +7,28 @@ def main():
117
print('\n\n')
128
search_for = input('search for: ') # Input string to search
139

14-
response = requests.get(f'http://api.duckduckgo.com/?q={search_for}&format=json') # Will send request with search_for variable
10+
response = requests.get(f'http://api.duckduckgo.com/?q={search_for}&format=json') # Send request with {search_for} variable
1511
response = response.json() # The result will be in json format
12+
# it will be in key, value pair which will be easy to find answers
1613

17-
# Printing search result here
18-
print('Heading:',response['Heading'])
19-
print('\nAbstract:',response['Abstract'])
14+
# Printing search result here we will print the values of keys inside brackets
15+
print('Heading:',response['Heading'])
16+
print('\nAbstract:',response['Abstract'])
2017
print('\nAbstract source:',response['AbstractSource'])
21-
print('\nAbstract text:',response['AbstractText'])
22-
print('\nDefinition:',response['Definition'])
18+
print('\nAbstract text:',response['AbstractText'])
19+
print('\nDefinition:',response['Definition'])
2320
print('Related Topic:')
2421

25-
related_no = 2 # Will show only no of text in realted topics
26-
for i in response['RelatedTopics']: # Will loop through Text in RelatedTopics
22+
related_no = 2 # Show only no of text in realted topics
23+
# Sometimes tere are less related topics so keep related no low
24+
for i in response['RelatedTopics']: # Loop through Text in RelatedTopics
2725
if related_no <= 0:
2826
break
2927
print(i['Text'])
3028
related_no = related_no - 1
3129

32-
3330
except KeyboardInterrupt: # ctrl+c will call KeyboardInterrupt and while loop will stop
31+
# it will stop execution of code and will print Exiting..
3432
print('\nExiting..')
3533
break
3634

0 commit comments

Comments
 (0)