[Sat Sep 14 2013]
*** You have joined channel #thelycaeum *** Users on #thelycaeum: Khmar DaReaper anto power-inside
*** #thelycaeum modes: +cnt
*** #thelycaeum was created on 2013-09-12 18:28:06
<Khmar> Okay.
*** anto (~anto@ has quit: Ping timeout: 264 seconds
<Khmar> I think this works better.
<power-inside> Yeah lol
<DaReaper> Yeah
<power-inside> I hear weird sounds in talky
<power-inside> on firefox 23.. my video preview looks fine though
<power-inside> Trying chrome now. ERC> /msg anto YOu there?
*** anto: No such nick/channel
<Khmar> Chrome should work. 
<Khmar> But mine keeps crashing
<power-inside> web RTC support first came to firefox AFAIK.. they should be
               covering it up well. <power-inside> My firefox crashed. :/
<Khmar> Firefox is lagging behind Chrome for most things from what I hear.
                                                                        [16:16]<Khmar> Which is a pity. <Khmar> Let's wait a while.
*** alfredpp (~alfredpp@ has joined channel #thelycaeum
ERC> /whois DaReaper 
*** DaReaper is - http://webchat.freenode.net
*** DaReaper is on channel(s): #thelycaeum 
*** DaReaper is/was on server herbert.freenode.net (DE)
ERC> /msg Chanserv Help
*** ChanServ (ChanServ@services.) has changed mode for #thelycaeum to +o Khmar
                                                                        [16:18]<alfredpp> hi
<Khmar> Hello alfredpp 
ERC> /whois alfredpp 
*** alfredpp is Alfred Paul (~alfredpp@
*** alfredpp is on channel(s): #thelycaeum 
*** alfredpp is/was on server rajaniemi.freenode.net (Helsinki, FI, EU)
*** alfredpp is logged in as alfredpp
<Khmar> Welcome. :)
<alfredpp> tried talky.io but it is not loading
*** guest4067 (75ebdcfe@gateway/web/freenode/ip. has joined
    channel #thelycaeum
<guest4067> Hi <guest4067> Anto here
<power-inside> Hi
<alfredpp> hi anto, guest4067  :)
<Khmar> guest4067: You can say /nick Anto to change your nick.
ERC> /who #thelycaeum
*** #thelycaeum guest4067  H
    75ebdcfe@gateway/web/freenode/ip. ( -
*** #thelycaeum alfredpp   H    ~alfredpp@ (Alfred Paul)
*** #thelycaeum Khmar      H@   ~user@ (Noufal Ibrahim
*** #thelycaeum DaReaper   H
    6da195d4@gateway/web/freenode/ip. ( -
*** #thelycaeum power-inside H    ~PowerInsi@ (Mohammed Irfan)
*** anto_ (~anto@ has joined channel #thelycaeum
<Khmar> Let's wait for 10 minutes or so to see how many people turn up.
                                                                        [16:20]<alfredpp> Ok
<power-inside> Okay.
<anto_> Ok
<Khmar> In the mean while, a round of introductions might be a good idea.
<anto_> Anto Jose here...antojose.com, from Thiruvananthapuram...met Noufal at
        PyCon2013 <alfredpp> Hi, I am Alfred, software engineer trainee at Zyxware Technologies,
           Trivandrum, hometown Thrissur
<DaReaper> Ok
<anto_> And I work with Alfred
<power-inside> Hi, I'm Irfan from Calicut. I'm doing B.tech in CSE. Now into
               3rd year at AWH Engg College Kuttikatoor.
<alfredpp> Co-worker of anto_  :)
ERC> /topic The official channel for http://thelycaeum.in. Please use http://bpaste.net/ if you want so show a code snippet or something from your screen. Please don't private message without asking.
*** Khmar (~user@ has set the topic for #thelycaeum: "The
    official channel for http://thelycaeum.in. Please use http://bpaste.net/
    if you want so show a code snippet or something from your screen. Please
    don't private message without asking."
<anto_> :)
<DaReaper> Hello, I'm Brijan from Mysore. I'm doing MBA from SDMIMD, Mysore.
                                                                        [16:22]<DaReaper> Hi irfan
<anto_> Hi!
<Khmar> I wanted to use the webrtc thing so that I could share my screen. Not
        particularly keen on audio. 
<Khmar> Looks like old fashioned text is the best.  <Khmar> Or maybe next time, I should try Google Hangouts. I've heard that it
        works better.
<anto_> ok
<DaReaper> Right.
*** guest4067 (75ebdcfe@gateway/web/freenode/ip. has quit:
    Ping timeout: 250 seconds
<alfredpp> Ok
<alfredpp> could we use skype? or teamviewer or something like that? *** sreekesh (~sreekesh@ has joined channel #thelycaeum <Khmar> Teamviewer is an option that some friends have recommended.
<Khmar> Hi sreekesh 
<sreekesh> hello
<Khmar> Skype is incredibly buggy.
<alfredpp> ok
<Khmar> It's 1626 by my watch. We'll start at 1630
<DaReaper> ok <anto_> ok
<alfredpp> Sure
<sreekesh> sure..
<Khmar> I think irc will work. The DGPLug has been conducting online trainings
        for several years now using just IRC dgplug.org/summertraining/2013
<Khmar> Also, if you do want to chat with developers, IRC is the medium. Not
        many get on talky or Skype to chat.
<Khmar> For example, I'm sure you can find some of the core Python programmers
        if you join the #python channel <alfredpp> That's true, I suggested teamviewer for screen sharing only
<alfredpp> Nevertheless, we could stick with IRC also :) <Khmar> Apparently, mibbit doesn't work well with freenode. *** suhail (~suhail@ has joined channel #thelycaeum
<anto_> http://webchat.freenode.net/
<Khmar> Hello suhail. Welcome.
<Khmar> Yes.
<suhail> Good evening .Finally configured
<Khmar> I recommended that.
<anto_> we can use this one
<suhail> using xchat
<Khmar> Nice. <Khmar> I expected some trouble since this is the first time I'm doing this.
*** SREEKESH_ (75cc650c@gateway/web/freenode/ip. has joined
    channel #thelycaeum
*** suhail_ (6f5c51e4@gateway/web/freenode/ip. has joined
    channel #thelycaeum
<Khmar> I wanted to iron those problems out before I start doing this on a mre
        regular basis. 
<Khmar> more* regular
<anto_> excitement covers up for all that for now *** suhail_ (6f5c51e4@gateway/web/freenode/ip. has left channel
    #thelycaeum: #thelycaeum
<Khmar> I just got a few emails asking about how to connect. 
<Khmar> So I think we'll wait a minute or two.
*** devanshug (71c16bb0@gateway/web/freenode/ip. has joined
    channel #thelycaeum
<anto_> ok <power-inside> kiwiirc.com is a better online option than mibbit. It's fast
               and much stable.
<SREEKESH_> so we are fixing this right?
<power-inside> fixing? what's broken?
<power-inside> screenshare? <SREEKESH_> i meant v are finalising about where to hold the workshop?
<Khmar> Right here.
<SREEKESH_> okay..
<power-inside> :)
ERC> /whois SREEKESH_ 
*** SREEKESH_ is - http://webchat.freenode.net
*** SREEKESH_ is on channel(s): #thelycaeum 
*** SREEKESH_ is/was on server herbert.freenode.net (DE)
<alfredpp> while installing pip install beautifulsoup4 i am getting this error
           "pip install beautifulsoup4" <alfredpp> Any idea?
<Khmar> Can you paste the complete error on bpaste.net and paste the link
<alfredpp> ok
<alfredpp> http://bpaste.net/show/0rE1JSXa8b8UjsbvOH9z/ *** SREEKESH_ (75cc650c@gateway/web/freenode/ip. has left
    channel #thelycaeum: #thelycaeum <Khmar> Can you put it on pastebin.com. For some reason, bpaste seems to be
        slow. <Khmar> Hmmm. *** Platinum (5faf5249@gateway/web/freenode/ip. has joined
    channel #thelycaeum
<Khmar> Did you try it again alfredpp? Sometimes, the mirrors don't work as
        reliably as they should. <Khmar> Hi Platinum
ERC> /whois Platinum 
*** Platinum is - http://webchat.freenode.net
*** Platinum is on channel(s): #thelycaeum 
*** Platinum is/was on server herbert.freenode.net (DE)
<alfredpp> http://pastebin.com/1DyZh9QP
<Platinum> hi team <alfredpp> trying now
<Khmar> Try it again. Do you see the same error?
<Khmar> Platinum: Can you tell us your name?
<Platinum> Sujatha
<Khmar> Welcome. <Platinum> thank uoi
<alfredpp> Khmar, still getting the same error ... :(
<Khmar> Which OS/Version of Python? <power-inside> try "beautifulsoup" without the 4.
<Khmar> Nope. That's a different library.
<Khmar> beautifulsoup4 has a different API and that's what we're going to
<power-inside> whoops. I had it installed. it was when I strugged to import
               "beautifulsoup4" and it didn't work (got your email fixing that
               though. ;)) <Khmar> I didn't want to spend setup time here on the channel which is why I
        sent the email and notes out in advance
<alfredpp> Khmar, Python 2.7.3
<alfredpp> Os - ubuntu 12/04
<power-inside> struggled*
<Khmar> alfredpp: Can you visit http://pypi.python.org/ <Khmar> That site?
<devanshug> same here I tried after downloading to import beautifulsoup4 but
            it gave an ImportError
<power-inside> import bs4
<power-inside> use "import bs4" in python rather than "import beautifulsoup4"
<Khmar> devanshug: Import bs4 <Khmar> devanshug: import bs4
<devanshug> (y) power-inside
<Khmar> alfredpp: Try running the install but say pip install --use-mirrors
<power-inside> devanshug: Was that a facebook "like" emoticon? --> (y) ? :) If
               so, you're welcome! <devanshug> :)
ERC> /ping alfredpp 
*** Ping time to alfredpp is 00:00.00
<Khmar> Did it work alfredpp?
<alfredpp> I am trying
<Khmar> k
<alfredpp> Sorry for making the delay <Khmar> From the error, it looks like you couldn't connect to
        pypi.python.org. The --use-mirrors should make pip search on all the
        PyPI mirrors. 
<Khmar> Try it and let me know. Let's start. 
<alfredpp> Ok
<Khmar> Welcome everyone. 
<Khmar> I'm doing this training as part of my workshops which I'm conducting
        under The Lycaeum banner. 
*** manco (~manco@ has joined channel #thelycaeum
<Khmar> Many people have complained about the distance problem (since I'm
        based in Calicut) so I want to do longer workshops partly online and
        partly offline. <Khmar> To do that, I'm experimenting with smaller workshops like this
<Khmar> And if they work, we can do the big ones. 
<Khmar> Okay.
<anto_> Okay
<Khmar> The notes for this workshop are at
<alfredpp> Khmar, Done <Khmar> alfredpp: Cool. :)
<Khmar> I'm going to run through that and we'll keep going till around
        1800. We'll stop then. 
<alfredpp> Okay
<Khmar> So, is there anyone here who doesn't know what Python is.
<Khmar> Guess not.  <Platinum> me
<Khmar> Python is a programming language. 
<Platinum> its all new to me
<Khmar> It's what people call a "scripting language" similar to things like
        Perl, Ruby, TCL etc.
<Khmar> But it has it's own strengths and weaknesses.
<Khmar> It's popular mainly in web space (sites like youtube, disqus etc. run
        on Python).
<Khmar> It's also got a good foot hold in the scientific computing space. 
<Khmar> Libraies like NumPY etc. are used heavily by non CS engineers for
        their daily work.  <Khmar> It's also good a good hold in the education space since it's easy to
<Khmar> I've been using Python since 2001 or so and think it's worth learning
        which is why I'm doing this training.
<Khmar> Platinum: What languages are you familiar with?
<Khmar> When you install Python, you get two things. The language
        compiler/interpreter itself.  <Platinum> c, c++,
<Platinum> very basic <Khmar> Which you can see if you type "python <ENTER>" at your prompt.
<Khmar> Platinum: Okay. Python is a higher level language than C/C++ so the
        experience will be different.
<Khmar> Can everyone see it?
<DaReaper> Yes.
<anto_> Yes
<alfredpp> Yes
<suhail> yes
<devanshug> Yes
<power-inside> Yep
<manco> yes
<Khmar> You should see something like "Python 2.7.3 (default, Jan  2 2013,
<Khmar> The "
<power-inside> 2.7.5 here.
<Khmar> Yeah. That's fine. <alfredpp> Yes
<sreekesh> yup
<Khmar> The >>> is the prompt and you can try simple stuff there.
<Khmar> Try typing this
<Khmar> print "Hello, world"
<Khmar> and hit enter. You should see the string printed.
*** suhail_ (6f5c51e4@gateway/web/freenode/ip. has joined
    channel #thelycaeum
<DaReaper> Yes.
<Khmar> Then try something like print 2+1
<manco> Done
<Khmar> you should see 3
<DaReaper> Yes.
<alfredpp> DOne
<Khmar> The is what we call the "interactive" mode.
<Khmar> And you can use it for small throwaway code. Just to try things out.
                                                                        [16:59]<Khmar> Please interrupt me if you don't follow.
<Khmar> If you sit quietly behind your keyboards, I won't know whether you've
        understood or not.
<Khmar> Okay.
<alfredpp> Sure
<anto_> ok
<manco> Okay
<DaReaper> Okay.
<power-inside> Ok.. I thought it's better to keep quiet to make the IRC less
<sreekesh> done
<devanshug> hmmm
<Khmar> power-inside: Yeah but feel free to ask relevant questions. <Platinum> ok
<power-inside> Sure.
<Khmar> Just don't "chat" :)
<power-inside> Understood :)
<Khmar> So, our task today is to write a program that fetches the National
        Geographic "Picture of the day" and sets it as our wallpaper.
        is the URL
<manco> wonderful
<DaReaper> Okay, nice. <Khmar> I thought it better to write a program that does something useful
        rather than just play around with "hello, world" programs.
<Khmar> anyway...
<DaReaper> May I know how will Python fetch the exact URL of the image from
           that link?
<Khmar> DaReaper: We'll come to that.
<DaReaper> Okay, thank you.
ERC> /whois DaReaper 
*** DaReaper is - http://webchat.freenode.net
*** DaReaper is on channel(s): #thelycaeum 
*** DaReaper is/was on server herbert.freenode.net (DE)
<Khmar> So... when you install Python, you get the interpter/compiler itself
        (that what you see when you type "python" and hit enter) <power-inside> Isn't this technique called web scraping?
<Khmar> and you get a "standard library"
<Khmar> power-inside: Yup.
<Khmar> The standard library is not unlike what you get with C. The C standard
        library gives you stuff like "printf" etc.
<anto_> ok <Khmar> The python stdlib (short for standard library) gives you a ton of
        "modules" (that's the Python term for a reusable library).
<manco> ok
<Khmar> Here is a list of the standard library
<Khmar> You can see how huge it is.  <Khmar> These things are usually installed on your system at
<anto_> ok
<Khmar> You can't (as a non privileged user) add or modify any of the modules
<Khmar> Take a look at that directory. Do you see lots of .py files?
<DaReaper> Yes py and .pyc files. <alfredpp> yes
<Khmar> Yeah. py files are python source files.
<manco> yes
<Khmar> .pyc files are compiled Python files. 
<DaReaper> Oh okay.
<Khmar> They're quicker to load up.
<DaReaper> Okay.
<Khmar> Now, we want to use some "third party libraries" to do our work. 
<Khmar> These are libraries outside the standard library written by various
        people for different purposes.  <Khmar> We use them to do things like fetch the page, figure out the image
<Khmar> To install them, we use a tool called "virtualenv"
<Khmar> virtualenv allows us to create an "evironment" into which we can
        install third party libraries.  <Khmar> We can do this without superuser privileges and without messing with
        our system Python libraries.
<alfredpp> like sandboxing?
<Khmar> alfredpp: Very lightweight sandboxing.
<alfredpp> okay
<Khmar> So, if I have a project called "natgeo", I can create a virtualenv
        called "natgeo" and install libraries inside that.  <Khmar> When I'm done, I can simply delete the virtualenv and be done with it.
<Khmar> My system python is not touched and everything works fine.
<Khmar> Clear?
<anto_> yup
<DaReaper> Yes.
<alfredpp> clear
<power-inside> uh okay
<devanshug> yes
<manco> yes
<Khmar> power-inside: Questions? <power-inside> what's wrong with installing 3rd party libs in
<sreekesh> oops i installed those 2 packages without setting up a virtual
<power-inside> they're seperate files?
<Khmar> power-inside: Yes but you have issues. Suppose I have a project natgeo
        that needs a third party library "requests"
<Khmar> power-inside: Suppose it needs requests version 0.5
<Khmar> and I have another project that needs version 0.6 <Khmar> Then what do I do?
<power-inside> Oh.
<Khmar> Suppose some chap makes a library with the same name as one of the
        standard library packages. What will happen then?
<power-inside> Ah okay
<manco> this avoids namespace issues too right?
<Khmar> Also, the standard library is "standard" and stable. Third party
        packages are often bleeding edge. You don't want to mix the two.
                                                                        [17:11]<Khmar> manco: What do you mean by namespace issues?
<sreekesh> so cant v hav  5.0 and 6.0 in the same library??
<alfredpp> If we install the 0.5 version in virualenv and after development we
           remove the library, the downloaded library will also go with that?
<manco> functions with the same names
<alfredpp> sorry not library, virtual environment
<alfredpp> If we install the 0.5 version in virualenv and after development we
           remove the environment, the downloaded library will also go with
           that? <Khmar> alfredpp: Yup. But pip has a command called "freeze" which can tell
        you what libs you have installed inside a certain venv and you can get
        recreate it easily.
<alfredpp> Okay
<Khmar> sreekesh: Because the library behaviour might have changed. 
<Khmar> sreekesh: Some programs might expect the behaviour with v0.5 and
        others with v0.6. 
<sreekesh> okay.. <Khmar> So, does everyone understand why we need virtualenv?
<suhail> yes
<alfredpp> yes
<Khmar> It's a standard Python practice.
<anto_> yes
<Khmar> so you should know what it's all about.
<manco> yes
<sreekesh> so can i delete  or uninstall the packages?
<DaReaper> yes
<devanshug> yups
<Khmar> sreekesh: Yup. "pip install" and "pip uninstall"
<sreekesh> :) <Platinum> i think you are too fast
<sreekesh> :)
<Platinum> Mr Kumar
<sreekesh> k..
<Platinum> Khmar*
<suhail> ls
<Khmar> Platinum: Do you have a specific question?
<suhail> oops sorry
<Platinum> i dint get what libraries mean <Khmar> power-inside: Also, the standard library evolves slower than the third
        party libs. It's more tested and conservative. The third party libs
        release faster. You might want the latest version of a library but you
        don't want to destabilise your Python install. So you can use
        virtualenv. <Khmar> Platinum: A library (the software term) is a collection of reusable
        code. In C for example, the standard C library gives you routines like
        "printf" etc. 
<Khmar> Platinum: You don't have to reimplement those functions. You can
        simply use them.
<Platinum> okay
<Khmar> Platinum: Python comes with a standard library which I linked to
        above. There are also libraries which other people write that are not
        part of the standard library. <Platinum> so he link u gave was for python.. an we use it exactly how its
<Platinum> okay
<Khmar> Platinum: That link was a list of standard library modules.
<Platinum> okay
<Khmar> Platinum: We try to not mix the two and to keep them isolated and
        separate use a tool called virtualenv. This allows us to create
        "environments" which can hold libraries.  <Khmar> Platinum: We can install whatever we want into them without affecting
        the standard library.
<Platinum> how do we do that
<Khmar> Okay... Let's move on. There's an extra tool called
        "virtualenvwrapper" which gives us a bunch of useful commands like
        "mkvirtualenv" (to make a virtualenv) and "workon" (to use a
        virtualenv) <Khmar> Platinum: That's what I'm going to talk about next.
<Platinum> okay
<Khmar> Platinum: Please don't wait to ask questions otherwise, I have to
        repeat myself. Ask as soon as you don't understand.
<Platinum> okay..done
<Khmar> I presume you've all got virtualenv and virtualenvwrapper installed? 
<alfredpp> yes <Khmar> If so, you should be able to first do this
<anto_> Yes
<devanshug> yes
<Khmar> . /etc/bash_completion.d/virtualenvwrapper <enter>
<Khmar> and then 
<Khmar> mkvirtualenv natgeo <enter>
<Khmar> The output should be something like
<Khmar> Hello? Does everyone have that working? <anto_> yes
<alfredpp> Yes.. Got it
<suhail> yes.but what is the . for?
<Platinum> ok <Platinum> yes
<suhail> ohk ohk i get it
*** power-inside (~PowerInsi@ has quit: Ping timeout: 262
<Khmar> suhail: The . is similar to "source"
<suhail> thank you
<Khmar> Once you have that, you've created a virtualenv and you can see that
        in your prompt.
<DaReaper> yes <anto_> yes
<Khmar> Your prompt will have (natgeo) in it. 
<alfredpp> yes
<Khmar> Try typing which python and hitting enter.
<Khmar> It will give you the interpreter inside the virtualenv.
<Platinum> yes
<Platinum> dint get you <Khmar> To get out of the virtualenv, type "deactivate" and hit enter
<anto_> ok
<Khmar> Platinum: Type "which python" and hit enter.
<Khmar> It will give you the path to the python interpreter and it will be
        inside your virtualenv.
<Platinum> oka... something like hostname?
<Khmar> Then exit the virtualenv by typing "deactivate" and hitting enter
<Khmar> hostname? <Khmar> And after you exit the virtualenv, try "which python" again. You can
        see that it will use the system python (/usr/bin/python or something)
<Khmar> Can you see it?
<Platinum> okay understood
<alfredpp> yes <suhail> yes
<DaReaper> yes
<sreekesh> yup..
<devanshug> yups
<Khmar> http://bpaste.net/show/132380/ is an example
<anto_> How do we come back to our previously created virtualenv?
<Khmar> anto_: You can say "workon natgeo". I forgot to mention that. Sorry.
<anto_> ok <Khmar> Now, install the libraries we need. We do this using the python
        installer program "pip"
<alfredpp> ok
<Khmar> Type "pip install requests beautifulsoup4"
*** power-inside (~PowerInsi@ has joined channel #thelycaeum
<Khmar> It will install the requests and beautifulsoup4 libraries into the
<Khmar> requests is an HTTP client library that we can use to fetch pages
                                                                        [17:28]<Khmar> welcome back power-inside 
*** gem (~nandaja@ has joined channel #thelycaeum
<Khmar> and beautifulsoup4 is a very resilient HTML parser library.
ERC> /whois gem 
*** gem is Nandaja Varma (~nandaja@
*** gem is on channel(s): #thelycaeum 
*** gem is/was on server adams.freenode.net (Budapest, HU, EU)
<Khmar> Hi gem
<gem> Hey Khmar :)
<gem> Khmar, I am Nandaja
<Khmar> Saw your name.  <devanshug> done, understood
<Khmar> So far so good.
<suhail> all done
<Khmar> Now, you can type python <enter>
<Khmar> and then try typing
<Khmar> import requests
<alfredpp> if i downloaded a library in one virtualenv and if i want to use
           the same another virtualenv, can we do that?
<Khmar> alfredpp: Nope. That's a requested feature but it's not there yet.
                                                                        [17:30]<alfredpp> okay
<Khmar> alfredpp: You need to install it inside ever virtualenv that you're
        going it use it in.
<alfredpp> Okay <Khmar> If you deactivate the virtualenv and then enter Python and try to
        "import requests", it will fail.
<Khmar> Okay?
<devanshug> is requests library by the same keneth reitz in Pycon India 2013?
                                                                        [17:32]<power-inside> Ok
<alfredpp> understood
<Khmar> devanshug: That's the one.
<Khmar> Now, we have all the stuff we need, we can get started.
<anto_> ok
<alfredpp> sure
<Platinum> ok
<Khmar> Open a file called ng_pod (For National Geographic picture of the day)
                                                                        [17:33]<Khmar> ng_pod.py
<alfredpp> inside python shell?
<manco> this is a new file right?
<anto_> how do we do that from the Python shell?
<Platinum> what is it..
<power-inside> make a file using your favourate editor.. not from python shell
<Platinum> dint get that
<power-inside> like "vim ng_pod.py" <Khmar> Not from within the python shell
<Khmar> but from a text editor. Create a new file.
<anto_> ok
<manco> got it
<alfredpp> ok
<Khmar> Thanks power-inside 
<Khmar> And type in the first program you see in
<Khmar> The snippet that starts with "import requests"
<alfredpp> done <devanshug> done <manco> comments in python are enclosed in quotes right?
<Khmar> The "import requests" statement is similar (atleast in effect if not
        implementation) to the C #include directive. "import" is a keyword. It
        tells Python to load that library (Python libraries are called
        "modules") and make it available to us.
<Khmar> manco: Nope. Comments start with #
<Khmar> manco: Strings are enclosed in quotes.
<manco> oh
<Khmar> # This is a comment
<Khmar> "This is a string"
<Khmar> In C, if you say #include <stdio.h>, you'll have the printf function
        available to you directly.  <DaReaper> okay
<Khmar> In Python, if you say "import requests", you'll have the requests
        module available but you have to say "requests.something" to access
        the "something" function. 
<Khmar> This is called "namespacing".
<alfredpp> Ok
<Khmar> All the functions and things inside the requests module are available
        under the "requests" namespace.
<Khmar> You could also say "import requests as rq" <manco> ok got it
<Khmar> Then you can say "rq.something"
<Khmar> Makes sense?
<alfredpp> how can we know which all functions are inside a library?
<Khmar> alfredpp: Read the documentation. :)
<manco> :)
<suhail> yes
<alfredpp> there is no other way, like man in linux?
<Khmar> alfredpp: Which you can do by typing help(requests) at the interpreter
        prompt (after importing the module)
<Khmar> alfredpp: man *is* reading the documentation. <manco> i have a question
<alfredpp> ok
<manco> the statements "Fetches the page..."
<Khmar> alfredpp: You can also do "pydoc requests"
<Khmar> manco: I'm coming to that.
<manco> ok <Khmar> But did you all understand the "import" statement?
<suhail> yes
<DaReaper> yes
<Khmar> Okay. 
<alfredpp> yes
<manco> yes
<power-inside> yes
<devanshug> yes
<Khmar> The next thing is the function definition. We're defining a function
        called "fetch_url"
<Khmar> The keyword "def" is used to define functions.
*** Pltinum (75fd9de1@gateway/web/freenode/ip. has joined
    channel #thelycaeum <Khmar> In Python, "blocks" (the stuff you demarcate in C using { and })
<Khmar> are handled using indentation.
<Khmar> So, the "body" of the function fetch_url has to be indented under it. 
<Khmar> You can use tabs or spaces but you *should* *be* *consistent*.
<anto_> ok *** suhail_ (6f5c51e4@gateway/web/freenode/ip. has left channel
    #thelycaeum: #thelycaeum
<Khmar> You can see how I've put all the statements inside the fetch_url 4
        spaces to the right.
<Khmar> Understand?
<suhail> yes
<anto_> yes
<power-inside> yep
<DaReaper> yes <manco> yes
<Khmar> Python is not a "free form" language. The format is rigid. Forces you
        to write neatly.
<power-inside> I love it :)
<Khmar> The "url" is a parameter to the fetch_url function.
<anto_> ok
<Khmar> Python is dynamically typed so you don't have to say something like
        "char * url" or "string url"
<manco> ok
<Khmar> The line immediately below that is a string called the "docstring"
                                                                        [17:44]<Khmar> It basically serves as documentation for the function.
<Khmar> It's not compulsory but it's good Python practice so try to do it.
<manco> how is it different from a comment?
<Khmar> I'll show you.
<manco> ok
<Khmar> But let's finish the rest of the function.
<Khmar> It's quite simple.
<manco> sure
<Khmar> We simply call the "get" function available inside requests to fetch
        the URL. <Khmar> We get it back as "r". This is a response object. 
<Khmar> It will have the HTTP headers and everything else.
<anto_> ok
<Khmar> We want just the actual content so we get that using r.content
<manco> ok
<Khmar> and we return that using the "return" keyword.
<alfredpp> hmm <Khmar> For details on the requests library API, you should read
<Khmar> Everyone with me so far?
<DaReaper> ok
<alfredpp> yes
<manco> yup
ERC> /who #thelycaeum
*** #thelycaeum Pltinum    H
    75fd9de1@gateway/web/freenode/ip. ( -
*** #thelycaeum gem        H    ~nandaja@ (Nandaja Varma)
*** #thelycaeum power-inside H    ~PowerInsi@ (Mohammed Irfan)
*** #thelycaeum manco      H    ~manco@ (Binny)
*** #thelycaeum Platinum   H    5faf5249@gateway/web/freenode/ip.
    ( - http://webchat.freenode.net)
*** #thelycaeum devanshug  H
    71c16bb0@gateway/web/freenode/ip. ( -
*** #thelycaeum suhail     H    ~suhail@ (Syed Suhail Ahmed)
*** #thelycaeum sreekesh   H    ~sreekesh@ (SREEKESH)
*** #thelycaeum anto_      H    ~anto@ (Anto Jose)
*** #thelycaeum alfredpp   H    ~alfredpp@ (Alfred Paul)
*** #thelycaeum Khmar      H@   ~user@ (Noufal Ibrahim
*** #thelycaeum DaReaper   H
    6da195d4@gateway/web/freenode/ip. ( -
<anto_> yes
<Khmar> Now, lets try this.
<Khmar> Save the file <Khmar> and then quit your editor.
<Khmar> go to your terminal and start python using "python <enter>"
<Khmar> The type "import ng_pod"
<Khmar> and hit enter.
<Khmar> It will load up the file which we just typed.
<Khmar> You can then access the fetch_url function using ng_pod.fetch_url
<Khmar> (Just like we accessed the requests.get function) <Khmar> So, try something like this
<alfredpp> should we give path to that file?
<Khmar> alfredpp: Which file?
*** power-inside (~PowerInsi@ has quit: Ping timeout: 260
<Khmar> Try something like this 
<alfredpp> ng_pod.py
<Khmar> alfredpp: It will look in the current directory first. So just make
        sure you launch the interpreter there.
<Khmar> Try something like this
<devanshug> done <Khmar> print ng_pod.fetch_url("http://thelycaeum.in")
<alfredpp> Ok
<Khmar> You should see it fetch the HTML for the Lycaeum website.
<anto_> wow!
<DaReaper> Yes
<alfredpp> yes
<suhail> k <Khmar> I can see you accessing the site. My webserver logs get lines of this
<sreekesh> cool
<Khmar> - - [14/Sep/2013:08:22:51 -0400] "GET / HTTP/1.1" 200
        2050 "-" "python-requests/1.2.3 CPython/2.7.3 Linux/3.2.0-52-generic"
<Khmar> :)
<Khmar> So far so good.
<Khmar> Makes sense?
<DaReaper> Yes
<alfredpp> yes
<anto_> yes@!
<sreekesh> sure does
<devanshug> yups <Khmar> Now, this is fine for library use but we want to just type "python
        ng_pod.py <enter>" on the command line.Not this whole import drama.
<Khmar> Try that.
<anto_> ok
<Khmar> Quit your interpreter and type "python ng_pod.py <enter>" on the
        command line
<Khmar> Nothing will happen. 
<Khmar> The reason is that we simply define the function but don't actually
        call it.
<alfredpp> hmmmm <Khmar> alfredpp: ?
<alfredpp> Sorry, got it
<Khmar> The third box at
<Khmar> has the program *** DaReaper_ (6da195d4@gateway/web/freenode/ip. has joined
    channel #thelycaeum
<Khmar> Can you add that and then try directly running the program from the
        command line?
<Khmar> You should be able to see a dump when you run the program.
<anto_> what dump? <anto_> Something kept the program running like waiting for sthg to complete
<Khmar> anto_: It's fetch the page. 
<anto_> but showed no output on the screen
*** DaReaper (6da195d4@gateway/web/freenode/ip. has quit: Ping
    timeout: 250 seconds <alfredpp> got it
*** power-inside (~power-ins@ has joined channel #thelycaeum
* power-inside is having BSNL connection problems during rain. :(
*** gem (~nandaja@ has quit: Ping timeout: 246 seconds
<Khmar> power-inside: Ah
<power-inside> what did I miss?
<manco> i got the same
<power-inside> At section 5?
<anto_> Khmar: is it supposed to show something on the screen? <Khmar> power-inside: Third program in section 5.
<alfredpp> anto_, the webpage
<manco> the one with the fetch url command right?
<Khmar> anto_: Sorry. No. We just run it. If we had said "print
        fetch_url(...)", we would have gotten some output.
<anto_> ok
<Khmar> power-inside: I'll send you all the complete irc chat transcript after
        this is over.
<sreekesh> yea..no output obtained
<anto_> :)
<anto_> ok <Khmar> sreekesh: But you must have noticed a small delay. That's the actual
        fetch happening.
<suhail> ok
<Khmar> There is a problem now. 
<manco> ok
<sreekesh> yea.. okay..
<anto_> yup
<Khmar> If you try the previous thing (start python and import ng_pod)
<Khmar> it will fetch the page. 
<Khmar> That's ugly.
<Khmar> I mean, you can import the library without it trying to hit the
<Khmar> Try it?
<Khmar> Just start python and say "import ng_pod" <anto_> tried
<manco> trid
<Khmar> it will wait for a while while it hits the network.
<anto_> yea
<Khmar> and then will finish the import.
<Khmar> That's not acceptable.
<Khmar> So, we use the if __name__ trick which you'll see in most Python
<Khmar> That's the next program in the notes.
<Khmar> Basically, __name__ is a special variable that always has the name of
        the current module being executed. <Khmar> If you "import" a module, it will have the name of the module (in our
        case, "ng_pod"
<Khmar> )
<Khmar> If you execute the module directly from the command line, it will have
<anto_> ok
<alfredpp> hmmm <alfredpp> ok
<Khmar> so, we stick an if condition that says if the __name__ is "__main__"
        (i.e. if we're running directly from the command line), call the
        fetch_url function.
<Khmar> Otherwise, don't do anything.
<Khmar> Does that make sense?
<alfredpp> yes
<suhail> nice
<manco> okay
<DaReaper_> yes
<Khmar> You can see the difference when you import and run now.
<Khmar> import will return immediately and not do anything. *** power-inside (~power-ins@ has quit: Ping timeout: 246
<Khmar> Running will actually fetch the page.
<Khmar> Clear?
<alfredpp> yes
<anto_> yes
<manco> yes
<suhail> yes <DaReaper_> yes
<Khmar> Okay. 
<Khmar> So now we have a simple fetcher.
<Khmar> Let's parse the HTML we get.
<anto_> yea :)
<alfredpp> ok
<suhail> ok
<DaReaper_> ok
<manco> k <Khmar>
<sreekesh> yea.. okay.
<devanshug> yeaps done
<Khmar> For this, we write a new function called "get_image_url". This will
        parse the HTML and return the url for the image we're interested in.
*** power-inside (~power-ins@ has joined channel #thelycaeum
<Khmar> If you open the page source and read it, you can see that there's a
        <div> tag with class "primary_photo". <Khmar> the actual <img> tag with the image is inside that.
<DaReaper_> yes
<Khmar> manco: I forgot to tell you the difference between a docstring and a
<Khmar> If, after importing the module, you do a "help(ng_pod.fetch_url)
        <enter>", you'll actually get the docstring as help text. <Khmar> You can also read the docstring directly like so "print
<manco> Khmar: Hmm <Khmar> This is used by tools like pydoc etc. to programmatically create
<Khmar> Comments are not part of the code and they're simply dropped off.
<manco> ok got it
<anto_> ok
<DaReaper_> oh okay
<alfredpp> ok
<Khmar> Finally, if you want to have multi line strings in Python, you can use
        triple quotes (""" or ''') <Khmar> That's what we're using here.
<anto_> ok
<DaReaper_> ok
<manco> ok
<Khmar> To do this, we use the Beautifulsoup library. We import it but we use
        a different form of the import
<Khmar> We say "from bs4 import BeautifulSoup" *** power-inside (~power-ins@ has quit: Ping timeout: 240
<Khmar> This means, import the bs4 module and then make bs4.BeautifulSoup
        available directly in the current namespace.
<Khmar> Okay? <DaReaper_> oh okay
<anto_> ok
*** gem (~nandaja@ has joined channel #thelycaeum
<anto_> one min
<suhail> good
<Khmar> Okay.
<manco> ok
<anto_> ok
<devanshug> ok
<anto_> What is the difference between a module and a library?
<Khmar> Inside the function, we first instantiate a BeautifulSoup object and
        we give it the page contents as a paramenter. 
<Khmar> anto_: library is a general term used in programming. Module is a
        Python specific term that refers to something you can import and
        use. http://docs.python.org/2/tutorial/modules.html <anto_> So bs4 is just somethng like requests? <Khmar> BeautifulSoup is a "class" which is a term form object oriented
        programming. We can "call" it like we would a function and it will
        create an "object" of type BeautifulSoup.
<Khmar> anto_: Yes. It's a module.
<Khmar> We pass it the page contents and then we can actually mess with the
        page. <anto_> ok
<Khmar> soup = BeautifulSoup(page)
<Khmar> Now we can call "methods" on the soup object to find parts of the
<Khmar> And that's what we do.
<Khmar> soup.find('div', class_ = 'primary_photo')  <Khmar> gives us the first 'div' tag with the class attribute set to
<DaReaper_> ok
<alfredpp> ok
<manco> ok
<Khmar> and then div.find('img')['src']
<Khmar> gives us the first "<img>" tag inside that and the "src" attribute of
        that tag.
<anto_> ok
<Khmar> Which is the URL we want.
<Khmar> We return that.
<Khmar> So we add the a call to get_image_url to the main program and we run
        it. <Khmar> Give it a shot, It should print the URL of the todays photo of the
<anto_> done
<Khmar> Can you see it? <Khmar> I'll wait for a minute.
<anto_> Yes, I see the light
<manco> yup
<alfredpp> yes
<Khmar> Cool.
<Khmar> The next step is to actuall fetch that image.
<DaReaper_> Wouldn't this create confusion if multiple images are on the page
            using the same class? <anto_> ok
<Khmar> DaReaper_: Yup but they aren't in this case. Screen scraping is always
        a matter of heuristics.
<Khmar> You'd have to think of something else then.
<Khmar> Is suhail still here?
<DaReaper_> Oh okay
<devanshug> yes i got a url in the reply. done
<Khmar> Cool. Now to fetch the image. We can reuse the "fetch_url" function to
        do that. <Khmar> If we say something like
        fetch_url(get_image_url(fetch_url("http://photography...."))), we will
        get the actual image.
<Khmar> Right?
<suhail> yes <devanshug> clear
<alfredpp> it should
<Khmar> So, we do something like that but in a slightly neater way.
<Khmar> That's the next program.
<manco> ok
<anto_> ok
<DaReaper_> yeah
<Khmar> page =
<Khmar> image_url = get_image_url(page)
<alfredpp> ok
<Khmar> image = fetch_url(image_url)
<Khmar> Right?
<Khmar> Now, need to store this in a file. <Khmar> To do that, we use the python "with" statement.
<anto_> ok
<Khmar> The "with" statement allows us to create what's called a "context" for
        an operation.
<Khmar> It can make some variables or behaviour available within the context
        and at the end of the context, automatically do clean up.
<Khmar> So, if I say with open("image.jpg") as f: ... <Khmar> it will open a file called "image.jpg" and make that file descriptor
        available as f
<Khmar> When the block is exited, the file will automatically be closed.
<anto_> ok
<Khmar> The old way of doing this is to say
<Khmar> f = open("image.jpg")
<Khmar> do_something_with(f)
<Khmar> f.close()
<Khmar> Nowadays, you'd say <Khmar> with open('image.jpg') as f:
<Khmar>      do_something_with(f)
<Khmar> Does that make sense?
<alfredpp> ok
<alfredpp> got the point
<anto_> yes
<Khmar> The with statement is useful for a lot of things like this. You'll see
        things like
<DaReaper_> yeah
<Khmar> with acquire_database_lock():
<Khmar>     do_something()
<Khmar> Which will run the function only if it gets the lock and then release
        it after that. <Khmar> Or maybe
<Khmar> with supress_output():
<Khmar>    run_some_heavy_ouput_function()
<Khmar> Which might supress the output of just that function.
<Khmar> "With" creates a context.
<suhail> ok
<anto_> ok
<alfredpp> ok
<devanshug> ok <Khmar> http://effbot.org/zone/python-with-statement.htm
<manco> ok
<DaReaper_> ok
<Khmar> So, what do we do? We fetch the image and then save it to a file
        called "image.jpg".
<Khmar> We open the file in "wb" (write + binary) since it's a jpg file.
                                                                        [18:24]<Khmar> Cool?
<Khmar> Try running the program.
<suhail> so far so good
<manco> great
<devanshug> done with running :)
<anto_> yes <Khmar> You should get an "image.jpg" file in your directory. Try viewing it.
<anto_> done
<DaReaper_> nice
<Khmar> Works?
<anto_> beautifully!
<suhail> getting some prob
<manco> yup
<devanshug> yes file name image.jpg is created in the same folder <Khmar> Okay. The next step is to set the background.
<suhail> ohk
*** Platinum (5faf5249@gateway/web/freenode/ip. has quit: Ping
    timeout: 250 seconds
<manco> i see the python byte code of the script as well <Khmar> This can be done using the "qiv" command
<Khmar> If you say "qiv --root_s <filename>"
*** riyas (3189836c@gateway/web/freenode/ip. has joined channel
<Khmar> it will set the background image to the <filename>
<anto_> ok
<Khmar> I don't know if Ubuntu and the whole Unity mess allows us to set it so
        easily <Khmar> but it works on normal X servers.
<manco> :)
ERC> /whois manco
*** manco is Binny (~manco@
*** manco is on channel(s): #thelycaeum 
*** manco is/was on server cameron.freenode.net (Vilnius, Lithuania, EU)
<Khmar> To set the background, we use the next program.
<DaReaper_> okay <Khmar> Basically, we write another function set_desktop_background
<Khmar> which receives the image name to set as the background.
<anto_> ok <Khmar> For this, we use the standard library "subprocess" module.
<Khmar> It allows us to execute commands and is quite commonly used in Python.
<manco> ok
<Khmar> We didn't install subprocess using pip since it's part of the standard
<alfredpp> ok <Khmar> So we simply import it on top and use it inside the
        set_desktop_background function
<anto_> ok
<Khmar> First, we construct the command we want to run command = "qiv --root_s
<Khmar> The %s inside the "s is substituted with the image_file (not unlike
        the printf format string in C).
<Khmar> So, the command would become "qiv --root_s image.jpg" <anto_> ok
<Khmar> Makes sense?
<Khmar> The subprocess.command function requires commands to be given as
<alfredpp> oh
<alfredpp> ok
<devanshug> sure
<Khmar> Lists are Python arrays. 
<Khmar> They're denoted using []
<Khmar> So [1,2,3] is a list" <DaReaper_> ok
<manco> ok
<Khmar> ["Noufal", "Ibrahim"] is a list of strings.
*** balasankarc (~balasanka@wikisource/Balasankarc) has joined channel
<Khmar> "Noufal Ibrahim" is a string
<Khmar> strings have a split method that break a string into smaller ones (by
        default on whitespace).
<Khmar> So, "Noufal Ibrahim".split() will return ["Noufal", "Ibrahim"]
<Khmar> "qiv --root_s image.jpg".split() will return ['qiv', '--root_s',
        'image.jpg'] <Khmar> 
<Khmar> Does that make sense?
*** power-inside (~p0wer-ins@ has joined channel #thelycaeum
<anto_> yes
<manco> yes
<alfredpp> yes
<Khmar> We pass that to the subprocess.command function to actually call it.
<Khmar> And modify our top level code to call the "set_desktop_background"
        function. <DaReaper_> yes
<alfredpp> ok
<Khmar> That should make the program work.
<Khmar> Try running it?
<alfredpp> I did get the image <alfredpp> but it is not set as background <Khmar> Ubuntu?
<manco> me neither
<alfredpp> yes
<Khmar> It uses some more complicate way of setting the background.
<manco> ubuntu
<alfredpp> and also i use gnome3 shell
<Khmar> You'll have to figure out the command yourself then.
<Khmar> The rest of the program will remain the same.
<sreekesh> ohh hmm.. <manco> ok
<Khmar> Sorry to spoil the climax. :)
<anto_> :D
<manco> no problemo
<manco> that was very informative
<alfredpp> :)
<Khmar> Ubuntu is not a particularly dev. friendly distribution anymore.
                                                                        [18:39]<manco> which one are you using Khmar ?
<Khmar> Debian.
<manco> ok
<Khmar> Now finally, leaving all that code under __name__ ... is ugly.
<Khmar> So we move that to a "main" function.
                                                                        [18:40]<Khmar> And we simply call the "main" function.
*** power-inside (~p0wer-ins@ has quit: Ping timeout: 246
<Khmar> from the __name__ part.
<anto_> ok
<alfredpp> ok <devanshug> ok
<sreekesh> k
<suhail> k
*** DaReaper_ (6da195d4@gateway/web/freenode/ip. has quit:
    Quit: Page closed
<Khmar> We use the exit function from the sys library.
<anto_> ok
<Khmar> And pass to it, the return value from main.
*** power-inside (~p0wer-ins@ has joined channel #thelycaeum
                                                                        [18:42]<alfredpp> so, while exit, it calls the main function and exits
<Khmar> "while exit"?
<Khmar> "main" is just a name I chose. It has no special meaning like in C.
*** suhail (~suhail@ has quit: Read error: Connection reset by
<alfredpp> means, when exit() is called, it interprets the function specified
           it and exits the program, Am i right? <Khmar> You can see how I'm calling sys.exit(main())
<Khmar> alfredpp: Nope. Sys.exit just returns with whatever value you give it.
<Khmar> sys.exit(2) returns 2 to the OS and exits.
<Khmar> I'm saying sys.exit(main())
<anto_> Will the code inside main() run without the exit(main()) line?
<alfredpp> Oh.. Ok
*** suhail (~suhail@ has joined channel #thelycaeum
<Khmar> THis calls main and then passes the return value of main as a
        parameter to exit
<Khmar> anto_: No <anto_> ok
<anto_> I think that was what Alfred was mentioning
<sreekesh> k
<Khmar> Does that make sense?
<alfredpp> can't use only main() ?
<anto_> yes!
<alfredpp> to call the function?
<Khmar> alfredpp: Yes. <Khmar> My code is like this now
<Khmar> return_value = main()
<Khmar> sys.exit(return_value)
<Khmar> I just compressed it into sys.exit(main())
<alfredpp> Ok
<Khmar> I'm using sys.exit since we might want to return different values to
        the OS for different conditions (e.g. error etc.)
<anto_> ok
<anto_> :)
<suhail> k
<Khmar> So, that's the program. <Khmar> I have two enhacements in the notes.
<anto_> okay!
<Khmar> And 3 pieces of homework you can try out and send back to the mailing
<Khmar> Look through them and email me noufal@thelycaeum.in for help. <alfredpp> Sure
<devanshug> sure
<sreekesh> okay..
<Khmar> Better mail the list. Since others will benefit too.
<anto_> ok
<sreekesh> sure..
<anto_> ok
<alfredpp> ok
<Khmar> Any other questions?
<alfredpp> just trying to figure out which command to set background in ubuntu
           .. :) <Khmar> IF you do fine out, please email the list with it.
<Khmar> Anything else?
<alfredpp> Ok
<suhail> going good
<devanshug> Can we ask our queries in the mailing lists too? <Khmar> Join the list and ask away.
<alfredpp> pwd
<alfredpp> oops
<alfredpp> sorry
<Khmar> Okay. Thanks for your time.
<Khmar> I hope it was beneficial for everyone
<Khmar> I'll post the chat transcript online with the notes.
<alfredpp> Thanks for a wonderful workshop.
<anto_> Thanks for Your time and effort!
<manco> Thanks for the information
<anto_> Thank You! <devanshug> yes it was very informative
<power-inside> Definitely! Thanks for taking the class. I'll check the
               transcript soon
<devanshug> thanks sir
<suhail> Thanks you very much.It was a great experience
<alfredpp> looking forward to hear from you again soon
<Khmar> If you think it was worth it, do let the other students at the college
        know so that they can attend further ones.
<alfredpp> Sure
<suhail> sure
<Khmar> Bye then and thanks.
<manco> sure
<manco> Take care