Beispiel #1
0
	def storeSelected(self):
		self.uniqueInserts = 0
		self.index = self.display.curselection()	#gets the index of elements user wishes to keep
		for x in range (0, len(self.index)):
			self.bibdata = Mx.marc2bib(self.collection, int(self.index[x]))	#extracts data
			self.xmlText = Mx.makeElem(self.collection, int(self.index[x]))	#gets xml text for corresponding xml element
			self.year = re.search("([0-9][0-9][0-9][0-9])", self.bibdata[2])	#regex to extract just the year
			cursor.execute("SELECT * FROM bibrec WHERE title=%s and author=%s", (self.bibdata[0], self.bibdata[1]))
			if (cursor.rowcount == 0):	
				self.uniqueInserts += 1
				if self.year is None:
					self.nYear = "NULL"
					cursor.execute("INSERT INTO bibrec (author, title, pubinfo, callnum, year, xml) VALUES (%s, %s, %s, %s, %s, %s)", (self.bibdata[1], self.bibdata[0], self.bibdata[2], self.bibdata[3], self.nYear, self.xmlText))
				else:
					cursor.execute("INSERT INTO bibrec (author, title, pubinfo, callnum, year, xml) VALUES (%s, %s, %s, %s, %s, %s)", (self.bibdata[1], self.bibdata[0], self.bibdata[2], self.bibdata[3], self.year.group(), self.xmlText))
		self.label.config(text="Records inserted to DB: "+str(self.uniqueInserts))
Beispiel #2
0
	def storeAll(self):
		self.uniqueInserts = 0
		for x in range (0, self.nrecs):	#loops through each record
			self.bibdata = Mx.marc2bib(self.collection, x)	#extracts data
			self.xmlText = Mx.makeElem(self.collection, x)	#gets xml text for corresponding xml element
			self.year = re.search("([0-9][0-9][0-9][0-9])", self.bibdata[2])	#regex to extract just the year
			#0 = title, 1 = author, 2 = pubinfo, 3 = callnum - date should be in 2
			cursor.execute("SELECT * FROM bibrec WHERE title=%s and author=%s", (self.bibdata[0], self.bibdata[1]))
			if (cursor.rowcount == 0):	
				self.uniqueInserts += 1
				if self.year is None:
					self.nYear = "NULL"
					cursor.execute("INSERT INTO bibrec (author, title, pubinfo, callnum, year, xml) VALUES (%s, %s, %s, %s, %s, %s)", (self.bibdata[1], self.bibdata[0], self.bibdata[2], self.bibdata[3], self.nYear, self.xmlText))
				else:
					cursor.execute("INSERT INTO bibrec (author, title, pubinfo, callnum, year, xml) VALUES (%s, %s, %s, %s, %s, %s)", (self.bibdata[1], self.bibdata[0], self.bibdata[2], self.bibdata[3], self.year.group(), self.xmlText))
		self.label.config(text="Records inserted to DB: "+str(self.uniqueInserts))