Skip to content
46 changes: 46 additions & 0 deletions APIScripts/DuckDuckGo it/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# DuckDuckGo it

## Aim

The main aim of the project is to search something without opening a browser.


## Purpose

This project is using DuckDuckGo API which will return search result without using browser.


## Short description of package/script

- API used is DuckDuckGo api https://duckduckgo.com/api.
- requests module is used for extracting data.
- It is a standalone script which will give search result.



## Workflow of the Project

First search term is taken from user and then it is searched by api after that Heading, Abstract, AbstractSource, AbstractText, Definition
and two Related Topic are shown as result.


## Setup instructions

Install Python Install all requirements by pip install -r requirements.py <br>
Run python duckduckgo_it.py


## Output

![Output_example1](images/Capture.PNG)


## Conclusion

This project will return the search result without opening browser.


## Author(s)

Atharva Bhandvalkar <br>
You can connect with me at : https://www.github.com/a-tharva
37 changes: 37 additions & 0 deletions APIScripts/DuckDuckGo it/duckduckgo_it.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import requests # This module will help extract data

def main():

while True:
try:
print('\n\n')
search_for = input('search for: ') # Input string to search

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

# Printing search result here we will print the values of keys inside brackets
print('Heading:',response['Heading'])
print('\nAbstract:',response['Abstract'])
print('\nAbstract source:',response['AbstractSource'])
print('\nAbstract text:',response['AbstractText'])
print('\nDefinition:',response['Definition'])
print('Related Topic:')

related_no = 2 # Show only no of text in realted topics
# Sometimes tere are less related topics so keep related no low
for i in response['RelatedTopics']: # Loop through Text in RelatedTopics
if related_no <= 0:
break
print(i['Text'])
related_no = related_no - 1

except KeyboardInterrupt: # ctrl+c will call KeyboardInterrupt and while loop will stop
# it will stop execution of code and will print Exiting..
print('\nExiting..')
break


if __name__ == '__main__':
main()
Binary file added APIScripts/DuckDuckGo it/images/Capture.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions APIScripts/DuckDuckGo it/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
requests