view importFromOpenMind/converter/addDRI.py @ 26:248bf8d1e2e7

make operations command-line configurable. parameters: infile outfile ops
author casties
date Thu, 24 Sep 2015 18:58:30 +0200
parents 124ef8f3b22d
children
line wrap: on
line source

from urllib import request

class converter:
    
    out ="/var/tmp/out.csv"
    url = "http://md.mpiwg-berlin.mpg.de/purls/search?q="  # /permanent/library/W028ATN3
    def read(self,fn):
        
        of = open(self.out,"w")
        
        fl = open(fn,"r")
        
        for line in fl.readlines():
            line = line.replace("\n","")
            line = line.replace('"','')
            splitted = line.split(",")
            
            path = splitted[0].replace('"','')
            path = path.replace("/mpiwg/online","")
            
            qr = self.url + path
            
            g = request.urlopen(qr, data=bytearray(path,"utf-8"))
            
            p = g.read().decode('utf-8')
            
            spl = p.split("\t")
            
            if len(spl) > 1:
                dri = spl[1]
                
                splitted.append(dri)
                
                print (splitted)
                
                of.write(",".join(splitted)+"\n")
                
        
        of.close()
            
        
            
        
cv =converter()

cv.read("/var/tmp/archive.csv")