async def index(request): mad_token = request.cookies.get("madToken") email = request.cookies.get("email") result = dao.check_login(email, mad_token) context = {"login_info": {"email": email}} if result else {} context["CDN_URL"] = CDN_URL return render_to_response("templates/index.html", context=context)
async def music(request): if request.query.get("ref"): context = { "ref": True, "music_list": json.dumps(os.listdir(MUSIC_FOLDER), ensure_ascii=False) } else: context = {"ref": False} context["CDN_URL"] = CDN_URL return render_to_response("templates/music/index.html", context=context)
async def get_page(cls, req): bg_color = req.query.get("bg_color") today_lines = req.query.get("today_lines", 3) demo = int(req.query.get("demo", 0)) scale = float(req.query.get("scale", 0.65)) margin_top = int(525 / 2 * (1 - scale)) margin_left = int(522 / 2 * (1 - scale)) gift_dict = {} price_dict = {} uid_to_uname_map = {} gift_list = await HansyGiftRecords.get_log() for uid, uname, gift_name, coin_type, price, count, *_ in gift_list: uid_to_uname_map[uid] = uname price_dict[gift_name] = price if gift_name not in gift_dict: gift_dict[gift_name] = {} if uid in gift_dict[gift_name]: gift_dict[gift_name][uid] += count else: gift_dict[gift_name][uid] = count gathered_gift_list = sorted([[ gift_name, sorted([[uid, count] for uid, count in senders.items()], key=lambda p: p[1], reverse=True) ] for gift_name, senders in gift_dict.items()], key=lambda x: price_dict[x[0]], reverse=True) gift_text = "" for gift_name, senders in gathered_gift_list: gift_text += f"{gift_name}: <br />" gift_text += "".join([ f" {uid_to_uname_map[uid]}: {count}<br />" for uid, count in senders ]) context = { "today_lines": today_lines, "bg_color": bg_color, "demo": demo, "scale": "%.2f" % scale, "margin_top": margin_top, "margin_left": margin_left, "guard_text": "", "gift_text": gift_text, } return render_to_response("templates/thank_v.html", context=context)
async def grafana(request): image_files = os.listdir("/home/wwwroot/statics/static/grafana/img/") music_files = os.listdir("/home/wwwroot/statics/static/grafana/music/") context = { "title": "grafana", "CDN_URL": CDN_URL, "background_images": ["/static/grafana/img/" + img for img in image_files], "background_musics": ["/static/grafana/music/" + mp3 for mp3 in music_files], } return render_to_response("templates/grafana.html", context=context)
def shared_page(request): key = request.match_info['key'] path = dao.get_shared_file(key) if not path or not os.path.exists(path): return HttpResponse("Cannot find file: %s" % path, status=404) try: with open(path, "rb") as f: content = f.read() except Exception as e: # TODO: add log. return HttpResponse(str(e), status=500) base_name, ex_name = os.path.splitext(path) ex_name = ex_name.lstrip(".") content_type = "application/octet-stream" if not ex_name: content_type = "text/plain" elif ex_name.lower() in ("md", "markdown"): content_type = "text/plain" else: for ex, content_t in STATICS_FILE_MIME_TYPE: if ex_name in ex.split(" "): content_type = content_t break if not content_type.startswith("text"): return HttpResponse(content, content_type=content_type) if type(content) != str: try: content = content.decode("utf-8") except Exception: content = u"未能读取文件内容,其中含有不能识别的编码。" title = base_name.split("\\" if os.name in ("nt", ) else "/")[-1] context_data = { "title": title, "detail": content, "need_trans": ex_name.lower() in ("md", "markdown"), "CDN_URL": CDN_URL } return render_to_response("templates/share.html", context=context_data)
async def old_blog(request): article_js_file_name = "" for f in os.listdir(DIST_ARTICLE_PATH): if f.lower().endswith(".js"): article_js_file_name = f break if DEBUG: article_js_link = os.path.join(DIST_ARTICLE_PATH, article_js_file_name) else: article_js_link = CDN_URL + "/static/article/" + article_js_file_name context = { "article_js_link": article_js_link, "page": { "author": "CL", "description": u"CL,编程爱好者,这是CL的官方博客,记录生活感悟和学习点滴。", "keywords": u"MADLIAR, CL, CL's 疯言疯语, 疯言疯语, 风言风语, CL博客", }, "CDN_URL": CDN_URL, } return render_to_response("templates/index.html", context=context)
async def console(request): context = { "title": "log", "CDN_URL": CDN_URL, } return render_to_response("templates/console.html", context=context)
async def game(request): return render_to_response("templates/game.html")
async def index(request): return render_to_response("templates/home.html", context={"CDN_URL": CDN_URL})