source: orga2redis.py @ 38:8a694e2a6847

Revision 38:8a694e2a6847, 1.9 KB checked in by hagenbruch@phoibe.ub.rub.de, 6 years ago (diff)

Version 0.3

Line 
1#! /usr/bin/env python
2# encoding: utf-8
3
4#  The MIT License
5#
6#  Copyright 2011 hagenbruch.
7#
8#  Permission is hereby granted, free of charge, to any person obtaining a copy
9#  of this software and associated documentation files (the "Software"), to deal
10#  in the Software without restriction, including without limitation the rights
11#  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12#  copies of the Software, and to permit persons to whom the Software is
13#  furnished to do so, subject to the following conditions:
14#
15#  The above copyright notice and this permission notice shall be included in
16#  all copies or substantial portions of the Software.
17#
18#  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19#  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20#  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21#  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22#  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23#  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24#  THE SOFTWARE.
25
26__author__="hagenbruch"
27__date__ ="$10.03.2011 13:30:37$"
28
29import logging
30import redis
31import urllib
32import simplejson as json
33
34logging.basicConfig (level=logging.DEBUG,
35                     format='%(asctime)s %(levelname)-4s %(message)s',
36                     datefmt='%a, %d %b %Y %H:%M:%S',
37                     )
38
39def fetch_data(myurl):
40    return json.loads(urllib.urlopen(myurl).read())
41
42def orga2redis(mydict):
43    r = redis.Redis(host='localhost', port=6379, db=0)
44    r.flushdb()
45    for pnd in mydict:
46        r.hset('pndorga', pnd.strip(), mydict.get(pnd))
47
48def main():
49    #orga2redis(fetch_data('http://134.147.247.36:8091/pnd_orgs/'))
50    orga2redis(fetch_data('http://bibliographie-admin.ub.rub.de/pnd_orgs/'))
51
52   
53if __name__ == "__main__":
54    main()
Note: See TracBrowser for help on using the repository browser.