analitics

Pages

Thursday, February 3, 2011

Read feed from sites.

Is a simple example for reading some feed.
I use two functions , first read url and secondary extract data.
This is the code source:

from xml.dom import minidom as dom
import urllib

def fetchPage(url):
    a = urllib.urlopen(url)
    return ''.join(a.readlines())


def extract(page):
    a = dom.parseString(page)
    item2 = a.getElementsByTagName('SendingDate')[0].firstChild.wholeText
    print "DATA ",item2
    item = a.getElementsByTagName('Cube')
    for i in item:
        if i.hasChildNodes() == True:
            e = i.getElementsByTagName('Rate')[10].firstChild.wholeText
            d = i.getElementsByTagName('Rate')[26].firstChild.wholeText
            print "EURO  ",e
            print "DOLAR ",d

if __name__=='__main__':
    page = fetchPage("http://www.bnro.ro/nbrfxrates.xml")

    extract(page)
Result is :

DATA  2011-02-03
EURO   4.2609
DOLAR  3.0921
This is all...

Python - calendar

Two simple example about calendar python module.
Show calendar 04 - 2011 :

>>> import calendar
>>> tc = calendar.TextCalendar(calendar.SUNDAY)
>>> print tc.formatmonth(2011,04)
     April 2011
Su Mo Tu We Th Fr Sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

>>>
Show calendar in HTML format :
>>> import calendar
>>> hc = calendar.HTMLCalendar(calendar.SUNDAY)
>>> print hc.formatmonth(2011,04)
;
The result is a HTML table with the calendar.
This is all .