def get_settings(self): if self.cache: return self.cache # Retrieve and cache session = getSession() self.cache = session.query(Setting).scalar() return self.cache
def update_settings(settings): session = getSession() current_settings = session.query(Setting).scalar() current_settings.blog_title = settings["blog_title"] current_settings.tag_line = settings["tag_line"] current_settings.meta_keywords = settings["meta_keywords"] current_settings.meta_description = settings["meta_description"] current_settings.items_per_page = settings["items_per_page"] current_settings.posts_in_home = settings["posts_in_home"] current_settings.cache_duration_in_seconds = settings["cache_duration_in_seconds"] current_settings.login = settings["login"] current_settings.password = settings["password"] current_settings.user_full_name = settings["user_full_name"] current_settings.user_email = settings["user_email"] current_settings.user_bio = settings["user_bio"] current_settings.user_short_name = settings["user_short_name"] current_settings.root = settings["root"] current_settings.google_analytics_code = settings["google_analytics_code"] current_settings.feed_burner_url = settings["feed_burner_url"] current_settings.bing_app_id = settings["bing_app_id"] current_settings.disqus_short_name = settings["disqus_short_name"] current_settings.disqus_url = settings["disqus_url"] try: session.add(current_settings) session.commit() s = Settings() s.clear(); return s.get_settings() except Exception, e: print e return None
def main(): downloader = DanmakuDownloader() s = models.getSession(config.DB_PATH) videos = s.query(models.Video).order_by(func.random()).all() for video in progressbar(videos): if os.path.exists(f'danmaku/{video.aid}.txt'): continue downloader.getAllDanmakuForVideo(video)
def wrap(*args, **kwargs): global app try: g.project_id = int(request.args.get('project_id', 0)) except: g.project_id = 0 setProject(g.project_id) g.session = getSession(g.project_id) return function(*args, **kwargs)
def tag(tagname): page = max(1, flask.request.args.get('page', 1, type=int)) sess = models.getSession(app.config['DB_PATH']) keys = getTags(sess) videos = getVideosByTag(tagname, page, sess) sess.close() return flask.render_template('browse.html', prefix='tag', key=tagname, keys=keys, videos=videos, page=page, pageoptions=getPageOptions(page))
def safe(key): page = max(1, flask.request.args.get('page', 1, type=int)) keys = ('adult', 'racy', 'spoof', 'medical', 'violence') sess = models.getSession(app.config['DB_PATH']) videos = getVideosByAnnotation(key, page, sess) sess.close() return flask.render_template('browse.html', prefix='safe', key=key, keys=keys, videos=videos, page=page, pageoptions=getPageOptions(page))
def getCount(q): session = getSession() connection = session.connection() resp = connection.execute("SELECT count(*) from(SELECT * FROM search where title LIKE '%" + q + "%' UNION SELECT * FROM search where content LIKE '%" + q + "%' ) WHERE published_at is not null") return resp.fetchone()
def search(q, offset, items_per_page): session = getSession() connection = session.connection() resp = connection.execute("SELECT * from(SELECT * FROM search where title LIKE '%" + str(q) + "%' UNION SELECT * FROM search where content LIKE '%" + str(q) + "%' ) WHERE published_at is not null ORDER BY published_at LIMIT " + str(items_per_page) + " OFFSET " + str(offset)) return resp.fetchall()
def __init__(self, queue, num): super().__init__() self.q = queue self.pbar = progressbar.ProgressBar(max_value=num) self.session = getSession(config.DB_PATH) self.count = 0
def __init__(self): self.session = requests.session() self.s = models.getSession(config.DB_PATH)
import sys import progressbar import models from_session = models.getSession('FROM_DB_PATH') to_session = models.getSession('TO_DB_PATH') TABLE = models.Label # Video, SafeAnnotation BATCH_SIZE = 1000 count = from_session.query(TABLE).count() print('total count:', count) for index in progressbar.progressbar( range(int(sys.argv[1]), count // BATCH_SIZE + 2)): query = from_session.query(TABLE)\ .order_by(TABLE.aid)\ .offset(index * BATCH_SIZE)\ .limit(BATCH_SIZE) try: videos = query.all() except Exception: print('current index: {}'.format(index)) raise for video in videos: to_session.merge(video) to_session.commit()