コード例 #1
0
ファイル: ajax_front.py プロジェクト: IthacaDream/nowater_web
    def POST(self):
        url = web.input(url="").url
        url = get_real_url(url)
        db = NovelDB()

        # baidu 有两种格式的url
        if url.startswith("http://tieba.baidu.com"):
            _id = re.search(r"\d+$", url).group()
            urls = [
                "http://tieba.baidu.com/p/%s" % _id,
                "http://tieba.baidu.com/f?kz=%s" % _id,
            ]
            _novel = max( db.get_novel_byurl(url) for url in urls )
        else:
            _novel = db.get_novel_byurl(url)

        if _novel:
            return simplejson.dumps({"status": "existed", "msg": "/novel/%s" % _novel.id})
        # 增加返回默认标签
        username, title, url, tag = get_thread_info(url)
        _novel = db.get_novel_byurl(url)
        if _novel:
            return simplejson.dumps({"status": "existed", "msg": "/novel/%s" % _novel.id})        
        if username and title:
            return simplejson.dumps({"status": "ok", "username": username, "title": title, "url": url, "tag": tag})
        return simplejson.dumps({"status": "error", "msg": "发生了错误,请检查地址的正确性"})
コード例 #2
0
    def POST(self):
        url = web.input(url="").url
        url = get_real_url(url)
        db = NovelDB()

        # baidu 有两种格式的url
        if url.startswith("http://tieba.baidu.com"):
            _id = re.search(r"\d+$", url).group()
            urls = [
                "http://tieba.baidu.com/p/%s" % _id,
                "http://tieba.baidu.com/f?kz=%s" % _id,
            ]
            _novel = max(db.get_novel_byurl(url) for url in urls)
        else:
            _novel = db.get_novel_byurl(url)

        if _novel:
            return simplejson.dumps({
                "status": "existed",
                "msg": "/novel/%s" % _novel.id
            })
        # 增加返回默认标签
        username, title, url, tag = get_thread_info(url)
        _novel = db.get_novel_byurl(url)
        if _novel:
            return simplejson.dumps({
                "status": "existed",
                "msg": "/novel/%s" % _novel.id
            })
        if username and title:
            return simplejson.dumps({
                "status": "ok",
                "username": username,
                "title": title,
                "url": url,
                "tag": tag
            })
        return simplejson.dumps({"status": "error", "msg": "发生了错误,请检查地址的正确性"})