from entity.DownloadInfoEntity import DownloadInfo from common.Utils import getSession from sqlalchemy import update class DownloadInfoService: def getOneNoFinish(): session = getSession() downloadInfo = session.query(DownloadInfo).filter( DownloadInfo.isFinished == 0, DownloadInfo.tryTime <= 2).first() session.close() return downloadInfo def getOneByVideoId(videoId): session = getSession() downloadInfo = session.query(DownloadInfo).filter( DownloadInfo.videoId == videoId).one_or_none() session.close() return downloadInfo def updateIsFinishByVideoId(videoId, tryTime, isFinish): session = getSession() updateSql = update(DownloadInfo).where( DownloadInfo.videoId == videoId).values(tryTime=tryTime, isFinish=isFinish) resutl = session.execute(updateSql) session.commit() session.close()