Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 12, 2021 06:21 pm GMT

BUILD A SIMPLE RESEARCH ASSISTANT WITH PYTHON

research gify img
Among other great stuffs we can do with python, research and information sourcing can be done better and faster with python. In this tutorial we are going to build a simple research assistant with a few lines of code.

Meanwhile, well be using a few python modules like Wikipedia and Pywhatkit to make this brief project fun and effective.

Firstly Let's Make Use Of Pywhatkit

Pywhatkit is a Python library with various helpful features. It is an easy to use library which does not require you to do some additional setup.

This module could also be used to send images and messages via whatsapp, play youtube videos, search the web, convert text to handwritten images and more. But for this brief tutorial we are basically going to use it to make a simple research assistant.

To get the full documentation on pywhatkit module click here

Pywhatkit doesnt come preinstalled with python, but can install it with pip or pip3 by simply running: pip install pywhakit on your command line.

Then import the module whenever you want to use it.

#import pywhatkitimport pywhatkit as kit#Get information about python in 5 lines/paragraphskit.info('python', 5)

The code above will give the following output:

Python is an interpreted high-level general-purpose programming language. Its design philosophy emphasizes code readability with its use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.Python is dynamically-typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly, procedural), object-oriented and functional programming. It is often described as a "batteries included" language due to its comprehensive standard library.Guido van Rossum began working on Python in the late 1980s, as a successor to the ABC programming language, and first released it in 1991 as Python 0.9.0.

That sounds like fun right? However, the 5 is for number of lines you need, you change it to whatever number you need.
But there is a little limitation here: Normally youd want to save the output to a variable or to a file and probably do something with it. However, before you do that, try and check the return type first. If you run save the search result to a variable and print the type, it'll be NonetType

Something like this:

import pywhatkit as kitsourced = kit.info('python', 5)print('
'*2)print(type(sourced))

Fortunately there is another better way, in case you'd like to save your search results to a variable, file or even send it as an email then you should use Wikipedia instead

Its actually similar to pywhatkit. You just install with pip: pip install wikipedia via command line, then you import the module.

Working With Wikipedia

Now let's code up something real fun:

#import wikipediaimport wikipedia as wk# #create a function to ask for language, word and sentence lines. Use the inputs to generate basic information# for the word entereddef find():    while True:        try:            lang = input('Please choose a language: "fr" for france, "es" for spanish and "en" for english:
') wk.set_lang(lang) word, sentence = input('Enter a word, space, followed by the number of lines you want(in figures):
').split() print(f'
Searching wikipedia for {word}...
') sourced = wk.summary(word, int(sentence)) print(sourced) except: print('Please make sure you entered a wikipedia compatible valid information with the following format: Programming 5. Separating the inputs with a space only. Also make sure you selected a valid LANGUAGE!') else: print('
......................................................
Research done!') break#run the functionfind()

Apparently both pywhatkit.info and wikipedia.summary are using the same knowledge base which is the official wikipedia, so you should not put any phrase or words that you wouldnt normally search on wikipedia. Its not google search engine. You may use .search instead of .summary to get search results from google(list format).

If haven't used the wikipedia library before, try and read the documentation here, it's actually precise and easy to understand, I strongly believe reading things up when necessary should be a major part of every programmer's skills.

OK guys.. This is just a simple research assistant program with python. Expect something more advanced on this same topic in the future.

If you'd like a more explained version of this post please visit the post page on my blog here.

Finally am kinda new here and this happens to be my first post on Dev, I'll be publishing more pythonic posts and your following up would be appreciated and would also make you see more of my posts.


Original Link: https://dev.to/geofspot/build-a-simple-research-assistant-with-python-4idb

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To