isis2marc.py

来自「开源MARC数据处理」· Python 代码 · 共 125 行

PY
125
字号
import sys, string, time
cmd = raw_input('\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n^_^  \n\nPlease re-check your parameters.\n\ni.e c:\python22\python ISIS2MARC.py someisis.txt marcfilenametosave.txt (if you have python)\n\ni.e. $ python ISIS2MARC.py someisisfile.txt marcfilename2sasve.txt (if you\'re in linux with python.)\n\nYou can use instead, the executable ISIS2MARC.exe in Windows\n\nTo use simply type ISIS2MARC someisis.txt marcfilenametosave.txt\n\nIf you didn\'t follow this combination\nJust press Ctrl-C\n\nContinue? Press Any Key\n\n\n') 
             
file = sys.argv[1]
file2 = sys.argv[2]

conf = open('isis2marcconf.txt', 'r')
conf.seek(0)
conf_content = conf.readlines()
split_old_li = string.split(conf_content[26],'=')
split_old_li_rep = string.replace(split_old_li[1],'\n','')
split_old_li_vals = string.split(split_old_li_rep,' ')


split_new_li = string.split(conf_content[27],'=')
split_new_li_rep = string.replace(split_new_li[1],'\n','')
split_new_li_vals = string.split(split_new_li_rep,' ')

split_rec = string.split(conf_content[63],'=')
split_rec_rep = string.replace(split_rec[1],'\n','')
split_fld = string.split(conf_content[64],'=')
split_fld_rep = string.replace(split_fld[1],'\n','')
split_sfl = string.split(conf_content[65],'=')
split_sfl_rep = string.replace(split_sfl[1],'\n','')


old_li_save = split_old_li_vals
new_li_save = split_new_li_vals

recs		= split_rec_rep
flds		= split_fld_rep
sfld		= split_sfl_rep

def comp(tags):
	
	old_tags = tags
	old_li = old_li_save
	new_li = new_li_save
	if tags in old_li:		
		pos_at_li = old_li.index(tags)
		tags = new_li[pos_at_li]	
	c = tags		
	return c


log = open(file2,'w') 
text = open(file, 'r')
content = text.read()
content = string.replace(content,recs,chr(29))
content = string.replace(content,flds,chr(30))
content = string.replace(content,sfld,chr(31))

content = string.replace(content,'\n','')
content = string.replace(content,chr(13),'')
split_tn = string.split(content,chr(29))
total_marc = content.count(chr(29))

rec = 0
fld = 0
mz = len(split_tn)
pointer = 1
finished = ''
for x in split_tn:	

	if pointer <= (mz-1): 
	
		
		print 'Converting ISIS record no. %s of %s. to MARC Done!...' % (pointer,mz-1)
		pointer = pointer + 1
		
		split_th = string.split(x,chr(30))				

		fld = 0
		p = 0
		q = 3
		tagp = 3
		tagq = 12
		
		data = ''
		directory = ''
		new_y = ''
		for y in split_th:		 				
			new_y = y
			if fld != 0: 					
				
				if y[:1]!=chr(31):
					new_y = '%ca%s' % (chr(31),y[0:])
					
				new_data = '%c00%s' % (chr(30),new_y)
				data = '%s%s' % (data,new_data)								
				
			split_to = string.split(y,chr(31))				
			
			header = x[:24]			
			
			if fld == 0: 					
				tag = y[24:]			
			else:							
				tags = tag[p:q]											
				new_directory = '%s%s' % (comp(tags),tag[tagp:tagq])
				tagp = tagp + 12
				tagq = tagq + 12				
				directory = '%s%s' % (directory,new_directory)
				
				p = p + 12
				q = q + 12
				
		
			fld = fld + 1
		finished =  '%s%s%s%c' % (header, directory,data,chr(29))		
		log.write('%s' % finished)
    
rec = rec + 1


print '\n\nDone! Thank you for using Phpmylibrary'
print '\n\nOpen your samplemarcoutput file to see converted MARC  data from ISIS Or.'
print '\n\nJust convert it to PhpMyLibrary using polGenSQL. After that you can just'
print '\n\nEx. mysql -uroot -hlocalhost -p phpmylibrarydb < phpmylibrary.sql'
print '\n\nAnd you\'re done! ISIS has been converted!'
print '\n\n\nPolerio Babao polerio@users.sourceforge.net'
print '\nhttp://phpmylibrary.sourceforge.net'
print '\n\n^_^ Thank your for your interest in PhpMyLibrary\n\n\n'
print 'Created during PhpMyLibrary-2.0.2 Oct 30, 2002\n'
cmd = raw_input('Press any key to exit!.') 			

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?