Webscraping using BeautifulSoup

Hi Friends today I have started using beautifulsoup to try to scrape a website.

To install beautifulsoup in fedora use the command

yum -y install python-BeautifulSoup.noarch

Use the following code to get the contents of a site :
import urllib2
from BeautifulSoup import BeautifulSoup
url = 'manualian.blogspot.com'
source = urllib2.urlopen(url)

This code reads the content of the site . And if you give source.read() you can get the content been gathered.
The urllib2 is a library to open urls.

Difference between Vim and Vi

I have often cam across these two editors . And hence I want to find the difference between these two : -

Vi : - This is a old form of editor . Where you can create a file, edit, save and delete .

Vim : - This also can do what vi can do . But the main difference is that it is compatible to most of the os . And it can be used for syntax highlighting of popular programming languages like python , C etc. It has many features than Vi.

How To Create A Static Home Page in Blogspot

Hi Friends,  to create a static home page in blogspot  I used the following techniques which will create a default home page in blogspot which is not actually a home page.

 The Steps I have used are :

1. Create the post with the content to be displayed at the home page.

2.  Then click the post options which we could see at the bottom.
         
3.Now change the sheduled date to future (TIll the date it should appear as home page.)
                                          

4.Now  click the design option . and change the number of posts on main page to 1.
                                      

Fedora Sound Problem resolved


Hi Friends today I have resolved the sound problem after installing fedora. Actually when I installed fedora there was sound but it was as low as I could not hear anything. I resolved the problem by using a fedora command alsamixer.

What I did was I used the alsamixer command on terminal which directed me to a screen which had the sound control graphs . Use the F6 key and change the default to HDA Intel which is input for me . Now increase the volume of master and front and this will increase the volume of speaker.

Easy Steps:

$alsamixer

-> use F6 to change to Intel HDA
-> change master and front to maximum

Factory design Pattern in Python


Hi Friends today I have learned about design patterns.

The Factory Design Pattern concepts are similar to factory concepts. (i.e,) In factory How small individual parts are manufactured and send to the main area like that . In python also the subclasses functions do the function according to the functions of the mainclass.

I have created an example program for the factory method in python : -

Here I have created a Movie factory , which used to create films and send results according to the queries from main class of movies. Have a check at the code I have tried.

MovieFactory code is : -

def Movies(type):
 if type == 5:
  class Predator:
   def director(input):
    print "The movie was directed by John McTiernan"
   def moviereview(input):
    print "The Movie was Good"
  return Predator()
 elif type == 4:
  class JurassicPark:
   def director(input):
    print "The movie was directed by Stefen speilberg"
   def moviereview(input):
    print "The film was Best"
  return JurassicPark()
 elif type == 3:
  class Avatar:
   def director(input):
    print "The movie was directed by James Cameroon"
   def moviereview(self):
    print"The film was good"
  return Avatar()

And the Main Class Movies code is : -

from moviefactory import Movies
a = Movies(5)
b = Movies(4)
c = Movies(3)
input = str(raw_input('''
Do you want to know the director of the film and its review
We have 3 films in our list Predator, Jurassic Park, Avatar
To know the director and film reviw, Press the Movie Name
'''))
if input == 'Predator':
 print a.director(), a.moviereview()
elif input == 'Jurassic Park':
 print b.director(), b.moviereview()
elif input == 'Avatar':
 print c.director(), c.moviereview()
else:
 print "you have misspelled the word"

Create your own commands and run in linux terminal using python


Using python you can create your own commands and run it using linux terminal. The steps are : -

1. Create a simple pragram like hello world . with the location of the python interpretor .

(For eg) : #!/usr/bin/python
# Filename : myfirstprogram.py
print "This is my FirstProgram !"

here # - is used as comment

And the line follwed with the symbols #! - is known as shebang line , This is used to tell the linux system that this program should run with that interpretor at the destination.

Now give the excecute permission using:

$ chmod a+x myfirstprogram.py

then run using

$./myfristprogram.py

o/p : This is my FirstProgram !

Then rename this program as myfirstprogram and it will still run when you excecute using terminal.

Now give the command $ echo $ path
/home/usr/bin:

you will get the location of the environment variable.
Now paste the program file in that location. And run the myfirstprogram in terminal it will run. You can now run this program from any location