Пример #1
0
def find_all_episodes():
    session = DBUtil.open_session()
    try:
        result = session.query(Episode).all()
        return result
    except Exception as e:
        print e
        session.rollback()
        return False
    finally:
        DBUtil.close_session(session)
Пример #2
0
def find_all_bangumis():
    session = DBUtil.open_session()
    try:
        result = session.query(Bangumi).all()
        return result
    except Exception as e:
        print e
        session.rollback()
        return None
    finally:
        DBUtil.close_session(session)
Пример #3
0
def find_all_senders():
    session = DBUtil.open_session()
    try:
        result = session.query(func.distinct(
            Danmaku.sender_id)).select_from(Danmaku).all()
        return result
    except Exception as e:
        print e
        session.rollback()
        return None
    finally:
        DBUtil.close_session(session)
Пример #4
0
def find_danmakus_by_sender_ids(sender_ids):
    session = DBUtil.open_session()
    try:
        result = session.query(Danmaku).filter(
            Danmaku.sender_id.in_(sender_ids)).all()
        return result
    except Exception as e:
        print e
        session.rollback()
        return None
    finally:
        DBUtil.close_session(session)
Пример #5
0
def find_danmakus_by_episode(episode_id):
    session = DBUtil.open_session()
    try:
        result = session.query(Danmaku).filter(
            Danmaku.episode_id == episode_id).order_by('playback_time').all()
        return result
    except Exception as e:
        print e
        session.rollback()
        return None
    finally:
        DBUtil.close_session(session)
Пример #6
0
def find_danmaku(danmaku):
    session = DBUtil.open_session()
    try:
        result = session.query(Danmaku).filter(
            Danmaku.raw_id == danmaku.raw_id).first()
        return result
    except Exception as e:
        print e
        session.rollback()
        return None
    finally:
        DBUtil.close_session(session)
Пример #7
0
def update_batch(batch):
    session = DBUtil.open_session()
    try:
        session.merge(batch)
        session.commit()
        return True
    except Exception as e:
        print e
        session.rollback()
        return False
    finally:
        DBUtil.close_session(session)
Пример #8
0
def add_episode(episode):
    session = DBUtil.open_session()
    try:
        session.merge(episode)
        session.commit()
        return True
    except Exception as e:
        print e
        session.rollback()
        return False
    finally:
        DBUtil.close_session(session)
Пример #9
0
def find_episodes_by_bangumi(bangumi_season_id):
    session = DBUtil.open_session()
    try:
        result = session.query(Episode).filter(
            Episode.season_id == bangumi_season_id).order_by("index").all()
        return result
    except Exception as e:
        print e
        session.rollback()
        return False
    finally:
        DBUtil.close_session(session)
Пример #10
0
def find_bangumi_by_id(season_id):
    session = DBUtil.open_session()
    try:
        result = session.query(Bangumi).filter(
            Bangumi.season_id == season_id).first()
        return result
    except Exception as e:
        print e
        session.rollback()
        return None
    finally:
        DBUtil.close_session(session)
Пример #11
0
def find_episodes_by_ids(episode_id_list):
    session = DBUtil.open_session()
    try:
        result = session.query(Episode).filter(
            Episode.episode_id.in_(episode_id_list)).all()
        return result
    except Exception as e:
        print e
        session.rollback()
        return False
    finally:
        DBUtil.close_session(session)
Пример #12
0
def add_danmakus(danmaku_list):
    session = DBUtil.open_session()
    try:
        for danmaku in danmaku_list:
            session.merge(danmaku)
        session.commit()
        return True
    except Exception as e:
        print e
        session.rollback()
        return False
    finally:
        DBUtil.close_session(session)
Пример #13
0
def find_fetch_logs_by_episode(episode_id):
    session = DBUtil.open_session()
    try:
        result = session.query(FetchLog).filter(
            FetchLog.episode_id == episode_id).order_by(
                FetchLog.batch.asc()).all()
        return result
    except Exception as e:
        print e
        session.rollback()
        return None
    finally:
        DBUtil.close_session(session)
Пример #14
0
def add_fetch_logs(fetch_log_list):
    session = DBUtil.open_session()
    try:
        for fetch_log in fetch_log_list:
            session.merge(fetch_log)
        session.commit()
        return True
    except Exception as e:
        print e
        session.rollback()
        return False
    finally:
        DBUtil.close_session(session)
Пример #15
0
def add_batch(batch):
    session = DBUtil.open_session()
    try:
        session.add(batch)
        session.commit()
        session.refresh(batch)
        return batch
    except Exception as e:
        print e
        session.rollback()
        return None
    finally:
        DBUtil.close_session(session)
Пример #16
0
    def __init__(self, handlers, tp, sp, ui):

        super().__init__(handlers,
                         template_path=tp,
                         static_path=sp,
                         ui_modules=ui,
                         debug=True)
        self.dbutil = DBUtil(**mysettings.settings['dbsetting'])
        self.q = multiprocessing.Queue()
        for _ in range(mysettings.settings['crawl_num']):
            p = multiprocessing.Process(target=crawlbyWord, args=(self.q, ))
            p.daemon = True
            p.start()
Пример #17
0
 def __init__(self, handlers, modules, tpath, spath):
     super().__init__(handlers=handlers,
                      ui_modules=modules,
                      template_path=tpath,
                      static_path=spath)
     self.db = DBUtil(**myconfigs.configs.get('dbconfig'))
Пример #18
0
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

from util.dbutil import DBUtil
import logging

DBUtil.init_db()
logger = logging.getLogger("logger")
Пример #19
0
#!/usr/bin/env python2.7
# -*- coding: utf-8 -*-

from tasks import index_page
from util.dbutil import DBUtil
from apscheduler.schedulers.blocking import BlockingScheduler

if __name__ == "__main__":
    db_util = DBUtil()
    db_util.init_db()
    index_page.index_page_spider()
    scheduler = BlockingScheduler()
    scheduler.add_job(index_page.index_page_spider, 'interval', minutes=120)
    scheduler.start()