Loading external libraries

An example where we are going to use the requests library and the xml.etree library to pull some content from the NYTimes website and display it in Blender.

The finished script will look something like this:

import bpy
import requests
from xml.etree import ElementTree as ElTree
from math import pi as PI   
# A function to draw some text    
def addText( t, loc, rot=(PI/2, 0, 0) ):
    bpy.ops.object.text_add( enter_editmode=True, location = loc, rotation = rot )
# Fetch the latest articles from NYTimes.com
req = requests.get('http://www.nytimes.com/services/xml/rss/nyt/HomePage.xml')
if( req.status_code == 200):
    # if the server responded correctly to our request
    rss = ElTree.fromstring(req.text)
    for i, title in enumerate(rss.iter('title')):
        #print(str(i) + ' ' + title.text)
        if ( i > 1 ):
            addText(title.text, (0, 0, i))