Esempio n. 1
0
	def write_to_database(self,m_group_id, m_group_id2, m_title, m_content, m_url, m_level):
		print 'write_to_database'
		'''doc = Documents.objects.filter(url = m_url)
		if (len(doc) == 0):
			doc = Documents(url=m_url, uid=self.uid, title=m_title, level = m_level)
			doc.save()
			print 'create\n'
		else:
			doc[0].uid = self.uid
			doc[0].title = m_title
			# doc.update()
			doc[0].save()
			doc = doc[0]
			print 'update\n'''
		# doc = Documents(title='title', url='url')
		# doc.save()
		# print 'docid is: %s' % str(doc)
		# Delete old records
		res = ResAddr()
		id = res.saveResaddr(m_url, m_level, '', m_title)
		doc = res.getById(id)
		oldContents = Contents.objects.filter(doc = doc)
		oldContents.delete()
		import types
		if type(m_content) is types.ListType:
			for para in m_content:
				# print 'm_content' + para
				con = Contents(group_id=doc.id, group_id2=m_group_id2, doc=doc, paragraph=para, tag='p')
				con.save()
		else:
			con = Contents(group_id=doc.id, group_id2=m_group_id2, doc=doc, paragraph=m_content, tag='p')
			con.save()
		return doc.id
Esempio n. 2
0
    def write_file_to_database(self, m_group_id, m_group_id2, m_title, m_path,
                               m_url, m_level):
        print 'write_to_database'
        '''doc = Documents.objects.filter(url = m_url)
		if (len(doc) == 0):
			doc = Documents(url=m_url, uid=self.uid, title=m_title, level = m_level)
			doc.save()
			print 'create\n'
		else:
			doc[0].uid = self.uid
			doc[0].title = m_title
			# doc.update()
			doc[0].save()
			doc = doc[0]
			print 'update\n'''
        # doc = Documents(title='title', url='url')
        # doc.save()
        # print 'docid is: %s' % str(doc)
        # Delete old records
        res = ResAddr()
        id = res.saveResaddr(m_url, m_level, '', m_title)
        doc = res.getById(id)
        oldContents = Contents.objects.filter(doc=doc)
        oldContents.delete()
        try:
            print '\n\n\nstart write url:', m_url
            reader = ReadBigFile(m_path, blockSize=1024 * 16)
            block = reader.getNextBlock()

            while (block != None):
                # print 'm_content' + para
                con = Contents(group_id=doc.id,
                               group_id2=m_group_id2,
                               doc=doc,
                               paragraph=unicode(block),
                               tag='p')
                con.save()
                block = reader.getNextBlock()
            os.remove(m_path)
            return doc.id
        except Exception as e:
            print e
            print str(e)
            exit()
            return None
Esempio n. 3
0
    def write_to_database(self, m_group_id, m_group_id2, m_title, m_content,
                          m_url, m_level):
        print 'write_to_database'
        '''doc = Documents.objects.filter(url = m_url)
		if (len(doc) == 0):
			doc = Documents(url=m_url, uid=self.uid, title=m_title, level = m_level)
			doc.save()
			print 'create\n'
		else:
			doc[0].uid = self.uid
			doc[0].title = m_title
			# doc.update()
			doc[0].save()
			doc = doc[0]
			print 'update\n'''
        # doc = Documents(title='title', url='url')
        # doc.save()
        # print 'docid is: %s' % str(doc)
        # Delete old records
        res = ResAddr()
        id = res.saveResaddr(m_url, m_level, '', m_title)
        doc = res.getById(id)
        oldContents = Contents.objects.filter(doc=doc)
        oldContents.delete()
        import types
        if type(m_content) is types.ListType:
            for para in m_content:
                # print 'm_content' + para
                con = Contents(group_id=doc.id,
                               group_id2=m_group_id2,
                               doc=doc,
                               paragraph=para,
                               tag='p')
                con.save()
        else:
            con = Contents(group_id=doc.id,
                           group_id2=m_group_id2,
                           doc=doc,
                           paragraph=m_content,
                           tag='p')
            con.save()
        return doc.id
Esempio n. 4
0
	def write_file_to_database(self,m_group_id, m_group_id2, m_title, m_path, m_url, m_level):
		print 'write_to_database'
		'''doc = Documents.objects.filter(url = m_url)
		if (len(doc) == 0):
			doc = Documents(url=m_url, uid=self.uid, title=m_title, level = m_level)
			doc.save()
			print 'create\n'
		else:
			doc[0].uid = self.uid
			doc[0].title = m_title
			# doc.update()
			doc[0].save()
			doc = doc[0]
			print 'update\n'''
		# doc = Documents(title='title', url='url')
		# doc.save()
		# print 'docid is: %s' % str(doc)
		# Delete old records
		res = ResAddr()
		id = res.saveResaddr(m_url, m_level, '', m_title)
		doc = res.getById(id)
		oldContents = Contents.objects.filter(doc = doc)
		oldContents.delete()
		try:
			print '\n\n\nstart write url:', m_url
			reader = ReadBigFile(m_path, blockSize=1024*16)
			block = reader.getNextBlock()

			while(block!=None):
				# print 'm_content' + para
				con = Contents(group_id=doc.id, group_id2=m_group_id2, doc=doc, paragraph=unicode(block), tag='p')
				con.save()
				block = reader.getNextBlock()
			os.remove(m_path)
			return  doc.id
		except Exception as e:
			print e
			print str(e)
			exit()
			return None