def freq_tops(): to_day = request.query.to intvl = request.query.intvl desc = request.query.api if intvl == '': intvl = 30 next_to_day, pre_to_day, days = compute_days(to_day, intvl) dbname = 'freq_tops_' + desc session = db.open(dbname) if session is None: print return "database is wrong " + dbname counts = [] session.close() for day in days: d = datetime.datetime.strptime(day, '%Y-%m-%d') sec = int(mktime(d.timetuple())) print day, sec entry = session.select({'timestamp': sec}) if entry is None: count = 0 else: count = int(entry[1][1]) counts.append(count) days = [day[5:] for day in days] print days, counts return template('tops_api', days=days, data=counts, interval=intvl, pre_to_day=pre_to_day, next_to_day=next_to_day, api=desc)
def index(page=None): '''分页获取数据''' if not page: page = 1 _entries = PicsService.get_list_by_page(page) _count = PicsService.get_count() _pagenavi = pages(_count, page) return template("index.html", handler=get_site_info(), entries=_entries, pagenavi=_pagenavi, template_settings = template_settings)
def admin(page=None): '''图片管理页面''' if not page: page = 1 _status = request.query.get('status', None) _entries = PicsService.get_list_by_page(page, admin=True, source=None, status=_status) _count = PicsService.get_count(admin=True, status=_status) _pagenavi = pages(_count, page) _pagenavi["param"] = request.query_string #url参数 return template("admin/pic-list.html", handler=get_site_info(), entries=_entries, pagenavi=_pagenavi, query = request.query)
def black_manage(page=None): '''黑名单管理''' if not page: page = 1 _type = request.query.get('type', None) _search = request.query.get('search', None) _entries = BlackListService.get_list_by_page(page, bType=_type, search=_search) _count = BlackListService.get_count(bType=_type, search=_search) _pagenavi = pages(_count, page) _pagenavi["param"] = request.query_string #url参数 return template("admin/black-list.html", handler=get_site_info(), entries=_entries, pagenavi=_pagenavi, query = request.query)
def user_manage(page=None): '''用户管理''' if not page: page = 1 _status = request.query.get('status', None) _search = request.query.get('search', None) _entries = UsersService.get_list_by_page(page, status=_status, search=_search) _count = UsersService.get_count(status=_status, search=_search) _pagenavi = pages(_count, page) _pagenavi["param"] = request.query_string #url参数 return template("admin/user-list.html", handler=get_site_info(), entries=_entries, pagenavi=_pagenavi, query = request.query)
def show(id): '''显示具体大图''' _data = PicsService.get_by_id(id) _sidebar_mostlike = PicsService.get_most_likes() _nav = dict(prev=None, next=None) if _data: _prev = PicsService.get_prev(_data['create_date']) _next = PicsService.get_next(_data['create_date']) _nav["prev"] = _prev _nav['next'] = _next _comments = CommentsService.get_by_pid(id) return template("show.html", handler=get_site_info(), entry=_data, sidebar_mostlikes=_sidebar_mostlike, template_settings = template_settings, nav=_nav, comments=_comments)
def index(page=None): '''分页获取数据''' if not page: page = 1 _entries = PicsService.get_list_by_page(page) _count = PicsService.get_count() _pagenavi = pages(_count, page) return template("index.html", handler=get_site_info(), entries=_entries, pagenavi=_pagenavi, template_settings=template_settings)
def admin(page=None): '''图片管理页面''' if not page: page = 1 _status = request.query.get('status', None) _entries = PicsService.get_list_by_page(page, admin=True, source=None, status=_status) _count = PicsService.get_count(admin=True, status=_status) _pagenavi = pages(_count, page) _pagenavi["param"] = request.query_string #url参数 return template("admin/pic-list.html", handler=get_site_info(), entries=_entries, pagenavi=_pagenavi, query=request.query)
def user_manage(page=None): '''用户管理''' if not page: page = 1 _status = request.query.get('status', None) _search = request.query.get('search', None) _entries = UsersService.get_list_by_page(page, status=_status, search=_search) _count = UsersService.get_count(status=_status, search=_search) _pagenavi = pages(_count, page) _pagenavi["param"] = request.query_string #url参数 return template("admin/user-list.html", handler=get_site_info(), entries=_entries, pagenavi=_pagenavi, query=request.query)
def black_manage(page=None): '''黑名单管理''' if not page: page = 1 _type = request.query.get('type', None) _search = request.query.get('search', None) _entries = BlackListService.get_list_by_page(page, bType=_type, search=_search) _count = BlackListService.get_count(bType=_type, search=_search) _pagenavi = pages(_count, page) _pagenavi["param"] = request.query_string #url参数 return template("admin/black-list.html", handler=get_site_info(), entries=_entries, pagenavi=_pagenavi, query=request.query)
def show(id): '''显示具体大图''' _data = PicsService.get_by_id(id) _sidebar_mostlike = PicsService.get_most_likes() _nav = dict(prev=None, next=None) if _data: _prev = PicsService.get_prev(_data['create_date']) _next = PicsService.get_next(_data['create_date']) _nav["prev"] = _prev _nav['next'] = _next _comments = CommentsService.get_by_pid(id) return template("show.html", handler=get_site_info(), entry=_data, sidebar_mostlikes=_sidebar_mostlike, template_settings=template_settings, nav=_nav, comments=_comments)
def freq_trends(): mini_labels_num = 5 delta = 30 #seconds to_day = request.query.to hours, to_day = get_hours_for_day(to_day) desc = request.query.api dbname = 'freq_trends_' + desc session = db.open(dbname) labels = [] if session is None: print return "database is wrong " + dbname counts = [] info = divide_hours(hours, mini_labels_num) time_array = info['times'] labels = info['labels'] for i in xrange(0, len(time_array)): sec = time_array[i] - delta start = time_array[i] - delta end = time_array[i] + delta total = 0 for sec in xrange(start, end): entry = session.select({'timestamp': sec}) if entry is None: continue total += int(entry[1][1]) ave = total / delta counts.append(ave) d = datetime.datetime.strptime(to_day, '%Y-%m-%d') pre_to_day = str(d - datetime.timedelta(days=1))[:10] next_to_day = str(d + datetime.timedelta(days=1))[:10] session.close() week_day = convert_week_time(to_day) return template('trends_api', hours=labels, data=counts, today=to_day, week=week_day, pre_to_day=pre_to_day, next_to_day=next_to_day, api=desc)
def admin_login(): '''后台用户登陆''' return template("admin/login.html", handler=get_site_info())
def user_change_password(): '''修改密码''' return template("admin/change-password.html", handler=get_site_info())
def option_manage(): '''站点基本设置''' _data = OptionsService.get_option('%s%s' % (MEMCACHE_KEY, '_option')) return template("admin/option.html", handler=get_site_info(), data=_data)
def option_manage(): '''站点基本设置''' _data = OptionsService.get_option('%s%s'%(MEMCACHE_KEY, '_option')) return template("admin/option.html", handler=get_site_info(), data=_data)
def _template(self, template): return bottle.template(template, vd=self.viewdata)
def play_trends(): return template("tops")
def index(): return template('portal')