source: make_pnd_list.py @ 0:2f43cb89e87c

Revision 0:2f43cb89e87c, 1.0 KB checked in by andre.hagenbruch@rub.de, 8 years ago (diff)

Initial commit for version 0.2

Line 
1#!/usr/bin/env python
2# encoding: utf-8
3"""
4make_pnd_list.py
5
6Created by Andre Hagenbruch on 2009-11-17.
7Copyright (c) 2009 University Library Bochum. All rights reserved.
8"""
9
10from urllib import urlopen
11
12def get_data():
13        pnd = {}
14        result = eval(urlopen('http://134.147.247.41:8983/solr/select/?q=*:*&fl=pnd+fach+fakultaet&wt=python&rows=150000').read())
15        docs = result['response']['docs']
16        for doc in docs:
17                #print docs
18                for person in doc.get('pnd', ''):
19                        #print person
20                        pnd.setdefault(person, {}).setdefault('fakultaet', doc['fakultaet'])
21                        pnd.setdefault(person, {}).setdefault('fach', doc ['fach'])
22        return pnd
23
24def make_csv(data):
25        #outfile = open('pnd.csv', 'w')
26        for person in data:
27                name, pnd = person.split('#')
28                print '%s;%s;%s;%s' % (name, pnd, data[person]['fakultaet'], data[person]['fach'])
29                #outfile.write('%s;%s;%s;%s\n' % (name.decode('utf-8'), pnd, data[person]['fakultaet'].decode('utf-8'), data[person]['fach'].decode('utf-8')))
30
31def main():
32        data = get_data()
33        make_csv(data)
34
35
36if __name__ == '__main__':
37        main()
38
Note: See TracBrowser for help on using the repository browser.