def __init__(self): """ Initializes database connection and sessionmaker Creates tables """ engine = db_connect() create_table(engine) self.Session = sessionmaker(bind=engine)
def __init__(self): """ Initializes database connection and sessionmaker Creates tables """ engine = db_connect() create_table(engine) self.Session = sessionmaker(bind=engine) logging.info("****SaveQuotePipeline: database connected****")
def saveLRUItems(): engine = db_connect() create_news_table(engine) DBSession = sessionmaker(bind=engine) session = DBSession() itemCount = len(mLRU) for itm in mLRU.values(): accmt = ACCommentCache(**itm) session.merge(accmt) session.commit() session.close() runLogging.info("%s items saved, before stop the reactor!" % itemCount)
def clearItemCache(): engine = db_connect() create_news_table(engine) DBSession = sessionmaker(bind=engine) session = DBSession() try: num_rows_deleted = session.query(ACCommentCache).delete() session.commit() print("%s items deleted!" % num_rows_deleted) runLogging.info("%s items deleted!" % num_rows_deleted) except: session.rollback() print("Could not clear table, rollback!") runLogging.info("Could not clear table, rollback!")
def loadLRUItems(): engine = db_connect() create_news_table(engine) DBSession = sessionmaker(bind=engine) session = DBSession() # query = session.query(ACComment).filter(ACComment.postDate+timedelta(hours=1) > datetime.now()) # items = query.all() mysqlClause = "SELECT * FROM actest2.accommentcache where postDate > DATE_SUB(NOW(), INTERVAL 1 day) order by postDate asc" accItems = session.execute(mysqlClause).fetchall() for accItm in accItems: itm = AcfunCommentItem() itm['cid'] = accItm[0] itm['acid'] = accItm[1] itm['quoteId'] = accItm[2] itm['content'] = accItm[3] itm['postDate'] = accItm[4] itm['userID'] = accItm[5] itm['userName'] = accItm[6] itm['userImg'] = accItm[7] itm['localImgPath'] = accItm[8] itm['count'] = accItm[9] itm['deep'] = accItm[10] itm['refCount'] = accItm[11] itm['ups'] = accItm[12] itm['downs'] = accItm[13] itm['nameRed'] = accItm[14] itm['avatarFrame'] = accItm[15] itm['isDelete'] = accItm[16] itm['isUpDelete'] = accItm[17] itm['nameType'] = accItm[18] itm['verified'] = accItm[19] cid = itm['cid'] mLRU[cid] = itm itemCount = len(accItems) print("%s items loaded, before start the reactor!" % itemCount) runLogging.info("%s items loaded, before start the reactor!" % itemCount) session.close()
def __init__(self): # engine = create_engine('mysql+mysqldb://root:ali88@localhost/actest', echo=True) engine = db_connect() create_news_table(engine) self.Session = sessionmaker(bind=engine)
def __init__(self): self.f = open("QiuShiBaike.txt", 'w+') self.connect = db_connect() cursor = self.connect.cursor() create_qiushi_table(cursor)