Skip to content

Instantly share code, notes, and snippets.

@denzuko
Forked from psychemedia/openulrLog2gource.py
Created March 12, 2014 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denzuko/9502260 to your computer and use it in GitHub Desktop.
Save denzuko/9502260 to your computer and use it in GitHub Desktop.
import csv
from time import *
#tr < openurlgource.csv -d '\000' > openurlgourcenonulls.csv ???deletes
#sed 's/\x0/ /g' openurlgource.csv > openurlgourcenonulls.csv
f=open('openurlgourcenonulls.csv', 'rb')
reader = csv.reader(f, delimiter='\t')
writer = csv.writer(open('openurlgource.txt','wb'),delimiter='|')
headerline = reader.next()
'''
for row in reader:
if row[4].strip() !='':
t=int(mktime(strptime(row[0]+" "+row[1], "%Y-%m-%d %H:%M:%S")))
#print row,row[4].rstrip(':'),row[4].replace(':','/'),t
writer.writerow([t,row[3],'A',row[4].rstrip(':').replace(':','/')])
'''
for row in reader:
if row[8].strip() !='':
t=int(mktime(strptime(row[0]+" "+row[1], "%Y-%m-%d %H:%M:%S")))
# row: 4 - issn, 5 - e-issn, 6 - isbn
if row[4]!='':
col='FF0000'
elif row[5]!='':
col='00FF00'
elif row[6]!='':
col='0000FF'
else:
col='666600'
if row[7]=='article' or row[7]=='journal':
typ='A'
elif row[7]=='book' or row[7]=='bookitem':
typ='M'
else:
typ='D'
agent=row[8].rstrip(':').replace(':','/')
#if agent=='':
# continue
#print row,row[4].rstrip(':'),row[7].replace(':','/'),t
writer.writerow([t,row[3],typ,agent,col])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment