Skip to content

Commit 2239d6f

Browse files
Merge pull request prathimacode-hub#1053 from a-tharva/DuckDuckGo-it
DuckDuckGo it
2 parents 65bf761 + 72ebd58 commit 2239d6f

File tree

4 files changed

+84
-0
lines changed

4 files changed

+84
-0
lines changed

APIScripts/DuckDuckGo it/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# DuckDuckGo it
2+
3+
## Aim
4+
5+
The main aim of the project is to search something without opening a browser.
6+
7+
8+
## Purpose
9+
10+
This project is using DuckDuckGo API which will return search result without using browser.
11+
12+
13+
## Short description of package/script
14+
15+
- API used is DuckDuckGo api https://duckduckgo.com/api.
16+
- requests module is used for extracting data.
17+
- It is a standalone script which will give search result.
18+
19+
20+
21+
## Workflow of the Project
22+
23+
First search term is taken from user and then it is searched by api after that Heading, Abstract, AbstractSource, AbstractText, Definition
24+
and two Related Topic are shown as result.
25+
26+
27+
## Setup instructions
28+
29+
Install Python Install all requirements by pip install -r requirements.py <br>
30+
Run python duckduckgo_it.py
31+
32+
33+
## Output
34+
35+
![Output_example1](images/Capture.PNG)
36+
37+
38+
## Conclusion
39+
40+
This project will return the search result without opening browser.
41+
42+
43+
## Author(s)
44+
45+
Atharva Bhandvalkar <br>
46+
You can connect with me at : https://www.github.com/a-tharva
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import requests # This module will help extract data
2+
3+
def main():
4+
5+
while True:
6+
try:
7+
print('\n\n')
8+
search_for = input('search for: ') # Input string to search
9+
10+
response = requests.get(f'http://api.duckduckgo.com/?q={search_for}&format=json') # Send request with {search_for} variable
11+
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
13+
14+
# Printing search result here we will print the values of keys inside brackets
15+
print('Heading:',response['Heading'])
16+
print('\nAbstract:',response['Abstract'])
17+
print('\nAbstract source:',response['AbstractSource'])
18+
print('\nAbstract text:',response['AbstractText'])
19+
print('\nDefinition:',response['Definition'])
20+
print('Related Topic:')
21+
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
25+
if related_no <= 0:
26+
break
27+
print(i['Text'])
28+
related_no = related_no - 1
29+
30+
except KeyboardInterrupt: # ctrl+c will call KeyboardInterrupt and while loop will stop
31+
# it will stop execution of code and will print Exiting..
32+
print('\nExiting..')
33+
break
34+
35+
36+
if __name__ == '__main__':
37+
main()
33.4 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests

0 commit comments

Comments
 (0)