Library Education Govt

Script to deal with rss xml feed of library.education.govt.nz


In [25]:
import requests
import json
import xmltodict
import bs4

In [2]:
reqlib = requests.get('https://library.education.govt.nz/rss/highlights')

In [3]:
reqlibt = reqlib.text

In [4]:
libtd = xmltodict.parse(reqlibt)

In [5]:
rslen = len(libtd['rss']['channel']['item'])

In [6]:
#rslen


Out[6]:
10

In [7]:
wrapdict = dict()

In [19]:
#print (libtd['rss']['channel']['item'][0])


OrderedDict([(u'title', u'Best schools in Auckland: 24 things to know before you choose a school'), (u'link', u'https://library.education.govt.nz/blogs/best-schools-auckland-24-things-know-you-choose-school'), (u'description', u'<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even" property="content:encoded"><p>By Simon Wilson<br />\n\tMetro Jul/August 2015: 40-49 <em>(article)</em></p>\n<p><span style="color: rgb(48, 48, 48); line-height: 20px;">Presents tables comparing Auckland secondary schools. Looks at school leaver qualifications and NCEA results, including University Entrance and Scholarship rates. Takes into account school decile, and whether Cambridge exams or the International Baccalaureate are offered as well as or instead of NCEA. Shows the new 2015 deciles.</span></p>\n<p><a href="http://library.education.govt.nz/cgi-bin/koha/opac-reserve.pl?biblionumber=51571" style="line-height: 18.5714282989502px; color: rgb(0, 120, 206); outline: dotted thin; outline-offset: -2px; background-color: rgb(255, 255, 255);">Request item</a></p>\n</div></div></div>'), (u'pubDate', u'Wed, 01 Jul 2015 20:46:34 +0000'), (u'dc:creator', u'tim.admin'), (u'guid', OrderedDict([(u'@isPermaLink', u'false'), ('#text', u'10833 at https://library.education.govt.nz')]))])

In [30]:
for libi in range(rslen):
    msjobdic = dict()

    #print (libtd['rss']['channel']['item'][libi]['title'])
    msjobdic.update({'title' : (libtd['rss']['channel']['item'][libi]['title'])})
    msjobdic.update({'link' : (libtd['rss']['channel']['item'][libi]['link'])})
    soupdes = bs4.BeautifulSoup(libtd['rss']['channel']['item'][libi]['description'])
    
    msjobdic.update({'description' : soupdes.text})
    msjobdic.update({'jsonlen' : libi})
    #findict = dict()
    
    #wrapdict.update({'title' : (libtd['rss']['channel']['item'][libi]['title'])})
    #totlen = len(libi)
    #for tes in range(totlen):
    #    wrapdict.update({'title' : txtspli[tes][1]})
    #findict.update({txtspli[0][0] : txtspli[0][1]})
    msjobz = msjobdic.copy()
    msjobz.update(msjobdic)
    
    wrapdict.update({libi : msjobz})
    #jsmsdob = json.dumps(wrapdict)
    
    
    #jslibi.update({rslen : msjobz})
    #jsmsdob = json.dumps(wrapdict)


Best schools in Auckland: 24 things to know before you choose a school
Tauira: Māori methods of learning and teaching
Dangerous liaisons
Bully beef
Could do better
What Candy Crush Saga teaches us about motivating employees
Influential Aucklanders in education
Explaining the achievement gap between indigenous and non-indigenous students: an analysis of PISA 2009 results for Australia and New Zealand
Panel-beaters don't have to learn Shakespeare
Leaders as decision architects

In [32]:
savjslib = json.dumps(wrapdict)

In [35]:
savjfin = open('/home/wcmckee/github/wcmckee.com/output/moelib/index.json', 'w')
savjfin.write(savjslib)
savjfin.close()

In [ ]: