Wikipedia on the terminal , using python

I wanted to get information on my terminal on Ubuntu. y requirement  was that, any  data that i wanted  should be output on the terminal itself. I didn’t want to open a browser each time i wanted some information. And all I needed was the data and not images and videos. So to view the information on the terminal was very convenient and efficient.

When i searched, I was looking for a python implimentstion , i came to know that using Wikipedia API, one can to send a http request to the website as a query action and json format and get the json object. This could be implemented using the request , module in python. So this would give the json object that had the data on the topic to be queried.

The next step was to parse it . And I found that Beautiful Soup can be used to do that so extract only the data. This was one of the best options available . An then the only thing to do was to print the data that is extracted.

I found 2 scripts to do just that. These scripts however dont use Requests module but use urllib and urllib2.
Advantage :
The advantage of using this is that, only a brief summary of the topic under search will be showed. And most of the time it is the only thing we want.

The second thing is that if there are sections in the topic, it will be shown.

Disadvantage :
What this lacks is that, it does not have a good pattern matching for searches, that is if it doesnt ind the exact words in the article it will not be returned. This also happens if each result has multiple result.
Sometimes the data returned is either very less or a lot.

Procedure:

First download and save tehse 2 python files.
wikipedia.py
    wiki2plain.py

Then create a python file and name it wiki.py . Then paste the following script in it.

from wikipedia import *
from wiki2plain import *

lang = ‘simple’
wiki = Wikipedia(lang)
try:
    data1 = raw_input(“enter searh query: “)
    raw = wiki.article(data1)
except:
    raw = None

if raw:
    wiki2plain = Wiki2Plain(raw)
    content = wiki2plain.text
    print content
else:
    print “No text returned”

Save it in the same folder as the other to files and run  wiki.py
Enter the search term and get the results.

Screenshots :

Screenshot from 2014-04-20 22:21:28

Screenshot from 2014-04-20 22:21:06

Advertisements

Interesting commands on Linux :SET 1

Here are some fun commands you can try on your Linux system probably when you are bored or want to try something new and something different. I really liked these commands and hope that you will enjoy using it too.

  1. cowsay
    you can make an image of cow appear on the terminal and  show any text that you want , as if the cow was saying it –
    So install cowsay using one of the following command :
    sudo apt-get install cowsay                     (for Debian based OS)
    yum install cowsay                                   (for Red Hat based OS)
    here is how the uoyput will look:
    cowsay1If you want to have a coloured cow to show any text install xcowsay .  Install it same way as cowsay but replace cowsay with xcowsay.
    Run it and ul get a coloured cow some where on your screen.
  2. Steam Locomotive (sl)
    this command “sl” runs a train across your terminal. Its really cool!!
    So install it using one of the commands:
    sudo apt-get install sl                            (In Debian like OS)
    yum -y install sl                                    (In Red Hat like OS)
    run the command  “sl” in he terminal, you should see something like this:
    sl2
  3. toilet
    This command itself is funny.. but what it does is takes a text string and builds the text in some different forms like using symbols some colours,etc
    To install use one of the command:
    sudo apt-get install toilet
    yum install
    toilet

    run the commands as :
    toilet seeTheSource
    toilet3or run the command: toilet -f mono12 -F metal seeTheSource
    toilet4
  4. telnet
    telnet is a network protocol and it causes stories to be run like some kind of animations. Nothing has to be installed here, all you need is a working internet condition.use the command:
    telnet towel.blinkenlights.nl
  5. cmatrix
    this command is used to create the matrix effect on a terminal.install it using the suitable command:

    sudo apt-get install cmatrix
    yum install cmatrix
    
    cmatrix
  6. espeak
    this command is used for text to speech. So you can configure it to be a welcome sound when your OS loads. Or use it to read text just like that.
    install espeak using one of:

     sudo apt-get install espeak 
     yum install espeakthen run it as: espeak "this is see the source" 
     or any other text you want. And have fun.

So all these commands are really fun to use, there are lots more available.. I will post about more useful commands in the coming posts!!

Animated desktop: For ubuntu 13.04 Raring /ubuntu 13.10 Saucy

An animated desktop looks amazing, and what can be more cooler than having the ability to setup an animated desktop with a video of your own choice??
This post will give the detailed steps to setup an animated desktop on Ubuntu 13.04 and 13.10 . The procedure works completely fine with older versions as well (but the older versions have an easier method). So to get the background live with a video of your choice , a few requirements have to be met. Few software have to be downloaded and installed. And  for videos which you have chosen to work , they must be in the .wmv video format.

Check out the video below to see how the animated desktop looks like. And follow the procedure below to make your desktop look like that. The link to the animations shown in the video is given at the end of this post. But remember this video is for Ubuntu 12.04 so the procedure for 13.04 and 13.10 is not this easy!!!

procedure for Ubuntu 13.04/13.10:–

step 1:
install the following software to support and play your video as a background. Copy paste these following lines one by one in the terminal :

  • sudo apt-get install mplayer
  • sudo apt-get install rar
  • sudo apt-get install unrar
  • sudo apt-get install ubuntu-restricted-extras
  • sudo apt-get install zenity

so this will install all the prerequisites that were needed. Since Zenity has some error, the installation cannot be done correctly on Ubuntu 13.04 and 13.10 which is why a different procedure has to be followed.

step 2:
Here we use the a-desk script for installation. the a-desk is a shell script that automates all the work that has to be done to set the desktop. So go ahead and download the a-desk zip folder from HERE .
Once downloaded extract it to get a folder named “ad” and place it where you want it to be. Now open the terminal and go to the location where you have stored the “ad” folder.
For example. if you have put he folder under /Home then use the command :
cd /home/ad

Once you are in the folder, run the shell script a-desk.installer using the following command:

sudo sh a-desk.installer

This will run the script and give you the options to select your language and the version. That is you can choose to get the 32bit version and 64 bit version .Once you select it it will start installing and once it is done  The “OK” button on the installer window will be highlighted. Click on it to finish the installation.

step 3:
Now go to the terminal and type the command :

~/.gnome2/nautilus-scripts/a-desk
This will open a window and you have to select the option atomic city. This will load the video atomic city to the background. Atomic city is a video that comes by default with he a-desk script.So thats it.. now you will have an animated desktop.

In my next post I will give the procedure to use customised videos as your animation for the desktop and also to change the animation to the videos present in the link given below!!

More amazing videos to setup from the background can be found from : HERE
Go to that website and download any video that you like and make it your animated desktop.

Disclaimer: When the animated desktop is setup , it doesn’t stay after the bootup. That is , this procedure doesn’t work on startup and you would have to repeat the procedure all over again to set it up. This is something I am working on and as soon as I find a solution, I will post it.