def getAllCrossRefLinks(self): sql = "SELECT src_article_id,keyword_id,des_article_id,des_item_id,des_attachment_id,src_content_type,src_origin_id,src_provider_id,src_isenglish,des_content_type,des_origin_id,des_provider_id,des_isenglish FROM cross_ref_link_en" try: self.cursor_stg.execute(sql) for row in self.cursor_stg.fetchall(): crossRefLink = CrossRefLink() crossRefLink.srcArticleId = row[0] crossRefLink.keywordId = row[1] crossRefLink.desArticleId = row[2] crossRefLink.desItemId = row[3] crossRefLink.desAttachmentId = row[4] crossRefLink.srcContentType = row[5] crossRefLink.srcOriginId = row[6] crossRefLink.srcProviderId = row[7] crossRefLink.srcIsEnglish = row[8] crossRefLink.desContentType = row[9] crossRefLink.desOriginId = row[10] crossRefLink.desProviderId = row[11] crossRefLink.desIsEnglish = row[12] yield crossRefLink except Exception, e: self.log.error(e)
def switchTableContent(self,fromTable='cross_ref_link_en',toTable='cross_ref_link_en_backup'): selectsql="SELECT src_article_id,keyword_id,des_article_id,des_item_id,des_attachment_id,src_content_type,src_origin_id,src_provider_id,src_isenglish,des_content_type,des_origin_id,des_provider_id,des_isenglish FROM %s;" % fromTable cleansql="delete from %s" % toTable try: self.cursor_stg.execute(cleansql) self.conn_stg.commit() self.cursor_stg.execute(selectsql) for row in self.cursor_stg.fetchall(): crossRefLink=CrossRefLink() crossRefLink.srcArticleId=row[0] crossRefLink.keywordId=row[1] crossRefLink.desArticleId=row[2] crossRefLink.desItemId=row[3] crossRefLink.desAttachmentId=row[4] crossRefLink.srcContentType=row[5] crossRefLink.srcOriginId=row[6] crossRefLink.srcProviderId=row[7] crossRefLink.srcIsEnglish=row[8] crossRefLink.desContentType=row[9] crossRefLink.desOriginId=row[10] crossRefLink.desProviderId=row[11] crossRefLink.desIsEnglish=row[12] addsql="replace into "+toTable+"(src_article_id,keyword_id,des_article_id,des_item_id,des_attachment_id,src_content_type,src_origin_id,src_provider_id,src_isenglish,des_content_type,des_origin_id,des_provider_id,des_isenglish) values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" % crossRefLink.toTuple() self.cursor_stg.execute(addsql) self.conn_stg.commit() except Exception,e: self.log.error(e)
def addCrossRefLink(self,article,targetArticle,keywordId=0,itemId=0,attachmentId=0): """ Add record to cross_ref_link @param article the article which has link to another article @param targetArticle @param keywordId @param itemId provision sequence number @param attachmentId """ crossRefLink=CrossRefLink() crossRefLink.srcArticleId=article.id crossRefLink.srcContentType=article.contentType crossRefLink.srcOriginId=article.originId crossRefLink.srcProviderId=article.providerId crossRefLink.srcIsEnglish=article.isEnglish crossRefLink.desArticleId=targetArticle.id crossRefLink.desContentType=targetArticle.contentType crossRefLink.desOriginId=targetArticle.originId crossRefLink.desProviderId=targetArticle.providerId crossRefLink.desIsEnglish=targetArticle.isEnglish crossRefLink.desAttachmentId=attachmentId crossRefLink.keywordId=keywordId crossRefLink.desItemId=itemId self.crossRefLinkDao.add(crossRefLink) self.queueDao.updateTargetArticleStatus(article.id,article.contentType)