def POST(self): form = novel_form() if not form.validates(web.input(_method="POST")): return render_to_response("admin/add_novel", { "form": form, }) else: args = web.input(_method="post", rid=None) next = "/tuoshui_admin/checkall" if args.rid: next = "/tuoshui_admin/checkall_recommends" del args.rid # 获得type args.type = get_type_by_url(args.url) if not args.type: return "type_error" ret = self.db.add_novel(args) if ret[0] is True: rid = web.input(_method="get", rid=None).rid # 修改推荐小说的状态 if rid: self.db.update_recommend_status(rid) raise web.seeother(next) else: return ret
def get_real_url(url): """ 获得真实的首页 """ url = url.strip() try: ntype = get_type_by_url(url) if ntype == 'baidu': prefix, qs = url.split("?", 1) args = urlparse.parse_qs(qs) # http://tieba.baidu.com/p/1040351223?pn=3 # if 'pn' in args and "tieba.baidu.com/p/" in prefix: if "tieba.baidu.com/p/" in prefix: url = prefix elif 'kz' not in args: url = "http://tieba.baidu.com/f?kz=%s" % "".join(args["z"]) else: url = "http://tieba.baidu.com/f?kz=%s" % DIGIT_RE.search( "".join(args['kz'])).group() if ntype == 'tianya': if url.split("/")[3] == 'techforum': if not TECH_RE.search(url): temp = url.split("/") temp.insert(-1, "1") url = "/".join(temp) if ntype == 'douban': url = url.split("?")[0] if not url.endswith("/"): url += "/" return url except Exception, e: return url
def get_real_url(url): """ 获得真实的首页 """ url = url.strip() try: ntype = get_type_by_url(url) if ntype == 'baidu': prefix, qs = url.split("?", 1) args = urlparse.parse_qs(qs) # http://tieba.baidu.com/p/1040351223?pn=3 # if 'pn' in args and "tieba.baidu.com/p/" in prefix: if "tieba.baidu.com/p/" in prefix: url = prefix elif 'kz' not in args: url = "http://tieba.baidu.com/f?kz=%s" % "".join(args["z"]) else: url = "http://tieba.baidu.com/f?kz=%s" % DIGIT_RE.search("".join(args['kz'])).group() if ntype == 'tianya': if url.split("/")[3] == 'techforum': if not TECH_RE.search(url): temp = url.split("/") temp.insert(-1, "1") url = "/".join(temp) if ntype == 'douban': url = url.split("?")[0] if not url.endswith("/"): url += "/" return url except Exception, e: return url
def POST(self): args = web.input() args.url = get_real_url(args.url) args.type = get_type_by_url(args.url) # args.email = args.email or "*****@*****.**" args.email = "" args.ip = self.ip db = NovelDB() ret = db.add_novel(args) if ret[0] is True: id = ret[1] start_work(id) return simplejson.dumps({"status": "ok", "id": id}) else: return simplejson.dumps({"status": "error", "msg": "发生了错误,请稍候再试"})
def get_thread_info(url): """ 获得小说信息,返回楼主和标题 2011/05/08 增加返回tag """ result = [None, None, url, ""] try: ntype = get_type_by_url(url) if ntype == 'baidu': result = get_baidu_info(url) elif ntype == 'tianya': result = get_tianya_info(url) elif ntype == 'douban': result = get_douban_info(url) except Exception, e: print traceback.format_exc()