Пример #1
0
    def __init__(self, conf, debug=False):
        handlers = [
            ('/', IndexHandler),
            ('/admin/drama/add', AdminDramaAddHandler),
            ('/admin/drama/list', AdminDramaListHandler),
            ('/admin/drama/search', AdminDramaSearchHandler),
            ('/admin/drama/parser', AdminDramaParserHandler),
            ('/api/drama/list', ApiDramaListHandler),
            ('/api/drama/search', ApiDramaSearchHandler),
            ('/drama/episode/play/(\S+)', DramaEpisodePlayHandler),
            ('/drama/episode/(\S+)', DramaEpisodeHandler),
            ('/weixin', WeixinHandler),
        ]
        settings = dict(template_path=os.path.join(os.path.dirname(__file__),
                                                   "./web/template"),
                        static_path=os.path.join(os.path.dirname(__file__),
                                                 "./web/static"),
                        debug=debug,
                        autoescape=None)
        self.conf = conf
        engine = MysqlEngine(conf.get('db.uri'))

        BaseModel.setup_all_model(engine)

        self.dramaModel = DramaModel.instance()
        self.episodeModel = DramaEpisodeModel.instance()

        self.dramaService = DramaService()
        self.wechat = WechatBasic(token=conf.get("wechat.token"),
                                  appid=conf.get("wechat.appId"),
                                  appsecret=conf.get("wechat.appSecret"))
        self.hashid = Hashids(salt="woshifyz")
        self.parser = {'tudou': TudouParser()}
        super(Application, self).__init__(handlers, **settings)
Пример #2
0
 def _fetch(self, url, year):
     text_content = self.get_decoded_html(url)
     content = pq(text_content)
     trs = content("#tg_box_con li")
     for tr in trs:
         tr = pq(tr)
         pic = HOST + tr("a img").attr("src")
         href = HOST + tr("a").attr("href")
         name = tr(".jd_info .tit a b").text()
         name = name.strip()
         if not name:
             print 'fyz error', url
             continue
         drama = DramaModel.instance().get_by_name(name)
         if not drama:
             actors = tr(".lionhover .right_info .actor").contents()[1]
             desc = tr(".lionhover .right_info .descr").contents()[1]
             print pic, name, year, href, actors, desc
             DramaModel.instance().insert(name, year, pic, actors, desc, href)
             drama = DramaModel.instance().get_by_name(name)
         self.dramaEpisodeSource.fetch(drama['id'], drama['source'])
Пример #3
0
 def fetch_list(self):
     url = "http://api.tv.sohu.com/v4/search/channel/sub.json?subId=19&&api_key=695fe827ffeb7d74260a813025970bd5&build=5.0.1.1&offset=0&page_size=100&partner=1&pay_type=0&plat=3&poid=1&sver=5.0.1"
     content = self.get_decoded_json(url)
     videos = content['data']['videos']
     sp = SohuParser()
     for v in videos:
         name = v['album_name']
         d = DramaModel.instance().get_by_name(name)
         score = 0
         try:
             score = int(float(v['score_tip'][:-3]) * 10)
         except:
             pass
         if not d:
             DramaModel.instance().insert(name, v['publish_time'][:4],
                                          v['hor_w16_pic'], v['main_actor'],
                                          v['album_desc'], v['aid'], score)
             d = DramaModel.instance().get_by_name(name)
         else:
             logging.info("set score %s for %s" % (score, d['id']))
             DramaModel.instance().set_score(d['id'], score)
         eps = DramaEpisodeModel.instance().get_by_drama_id(d['id'])
         if eps:
             sp.parse_album_by_aid(d['id'], v['aid'], eps[-1]['episode'])
         else:
             sp.parse_album_by_aid(d['id'], v['aid'])
Пример #4
0
 def fetch_list(self):
     url = "http://api.tv.sohu.com/v4/search/channel/sub.json?subId=19&&api_key=695fe827ffeb7d74260a813025970bd5&build=5.0.1.1&offset=0&page_size=100&partner=1&pay_type=0&plat=3&poid=1&sver=5.0.1"
     content = self.get_decoded_json(url)
     videos = content["data"]["videos"]
     sp = SohuParser()
     for v in videos:
         name = v["album_name"]
         d = DramaModel.instance().get_by_name(name)
         score = 0
         try:
             score = int(float(v["score_tip"][:-3]) * 10)
         except:
             pass
         if not d:
             DramaModel.instance().insert(
                 name, v["publish_time"][:4], v["hor_w16_pic"], v["main_actor"], v["album_desc"], v["aid"], score
             )
             d = DramaModel.instance().get_by_name(name)
         else:
             logging.info("set score %s for %s" % (score, d["id"]))
             DramaModel.instance().set_score(d["id"], score)
         eps = DramaEpisodeModel.instance().get_by_drama_id(d["id"])
         if eps:
             sp.parse_album_by_aid(d["id"], v["aid"], eps[-1]["episode"])
         else:
             sp.parse_album_by_aid(d["id"], v["aid"])
Пример #5
0
 def _fetch(self, url, year):
     text_content = self.get_decoded_html(url)
     content = pq(text_content)
     trs = content("#tg_box_con li")
     for tr in trs:
         tr = pq(tr)
         pic = HOST + tr("a img").attr("src")
         href = HOST + tr("a").attr("href")
         name = tr(".jd_info .tit a b").text()
         name = name.strip()
         if not name:
             print 'fyz error', url
             continue
         drama = DramaModel.instance().get_by_name(name)
         if not drama:
             actors = tr(".lionhover .right_info .actor").contents()[1]
             desc = tr(".lionhover .right_info .descr").contents()[1]
             print pic, name, year, href, actors, desc
             DramaModel.instance().insert(name, year, pic, actors, desc,
                                          href)
             drama = DramaModel.instance().get_by_name(name)
         self.dramaEpisodeSource.fetch(drama['id'], drama['source'])
Пример #6
0
    def __init__(self, conf, debug=False):
        handlers = [
            ('/', IndexHandler),
            ('/admin/drama/add', AdminDramaAddHandler),
            ('/admin/drama/list', AdminDramaListHandler),
            ('/admin/drama/search', AdminDramaSearchHandler),
            ('/admin/drama/parser', AdminDramaParserHandler),

            ('/api/drama/list', ApiDramaListHandler),
            ('/api/drama/search', ApiDramaSearchHandler),

            ('/drama/episode/play/(\S+)', DramaEpisodePlayHandler),
            ('/drama/episode/(\S+)', DramaEpisodeHandler),

            ('/weixin', WeixinHandler),
        ]
        settings = dict(template_path=os.path.join(os.path.dirname(__file__), "./web/template"),
                        static_path=os.path.join(os.path.dirname(__file__), "./web/static"),
                        debug=debug,
                        autoescape=None
                        )
        self.conf = conf
        engine = MysqlEngine(conf.get('db.uri'))

        BaseModel.setup_all_model(engine)

        self.dramaModel = DramaModel.instance()
        self.episodeModel = DramaEpisodeModel.instance()

        self.dramaService = DramaService()
        self.wechat = WechatBasic(token=conf.get("wechat.token"), appid=conf.get("wechat.appId"),
                                  appsecret=conf.get("wechat.appSecret"))
        self.hashid = Hashids(salt="woshifyz")
        self.parser = {
            'tudou': TudouParser()
        }
        super(Application, self).__init__(handlers, **settings)
Пример #7
0
 def get_drama_infos(self, count, offset):
     dramas = DramaModel.instance().list_avalable(count, offset)
     for drama in dramas:
         eps = DramaEpisodeModel.instance().get_by_drama_id(drama.id)
         drama["eps"] = eps
     return dramas
Пример #8
0
 def new_drama(self, count=10):
     eps = DramaEpisodeModel.instance().new_drama(count=count)
     for ep in eps:
         ep["drama"] = DramaModel.instance().get_by_id(ep.drama_id)
     return eps
Пример #9
0
 def search_by_name(self, name, count):
     dramas = DramaModel.instance().search_by_name(name, count)
     for drama in dramas:
         eps = DramaEpisodeModel.instance().get_by_drama_id(drama.id)
         drama["eps"] = eps
     return dramas
Пример #10
0
 def get_drama_infos(self, count, offset):
     dramas = DramaModel.instance().list_avalable(count, offset)
     for drama in dramas:
         eps = DramaEpisodeModel.instance().get_by_drama_id(drama.id)
         drama['eps'] = eps
     return dramas
Пример #11
0
 def new_drama(self, count=10):
     eps = DramaEpisodeModel.instance().new_drama(count=count)
     for ep in eps:
         ep['drama'] = DramaModel.instance().get_by_id(ep.drama_id)
     return eps
Пример #12
0
 def search_by_name(self, name, count):
     dramas = DramaModel.instance().search_by_name(name, count)
     for drama in dramas:
         eps = DramaEpisodeModel.instance().get_by_drama_id(drama.id)
         drama['eps'] = eps
     return dramas