예제 #1
0
    def export_html(self, path, override=True):
        prefix = os.environ.get('file_prefix', '')
        new_url = "medias/%s%s.html" % (prefix, self.id)
        fname = os.path.join(path, new_url)
        if override is False and os.path.exists(fname):
            logging.debug("export %s, ignored" % fname)
            return new_url
        self.retrieve()
        try:
            j = json.loads(self.data)
        except:
            self.set_err(ErrCode.DATA_INVALID, "export_html() fail to load "
                         "response data to json")
            return "#None"
        content = {}
        if 'title' not in j:
            self.set_err(ErrCode.DATA_INVALID, "export_html() no title "
                         "field found")
            return "#None"
        content['title'] = j['title']
        content['num'] = len(j['videos'])
        iqiyi_re = re.compile(r'qiyipic')
        picture = j['image_post_url']
        m = iqiyi_re.search(picture)
        if m:
            content['pic'] = dump_pic(picture)
        else:
            content['pic'] = picture
        content['content'] = j['summary']
        content['create_time'] = str(datetime.now())[:19]
        content['actors'] = " | ".join(j['actor'])
        content['category'] = j['category']
        content['tag'] = " | ".join(j['child_category'])
        media_id = j['id']
        if len(j['videos']) == 0:
            self.set_err(
                ErrCode.DATA_INVALID, "export_html() fail to get video info,"
                " video number is 0")
            return "#None"
        video_id = j['videos'][0]['id']
        content['history_url'] = settings.HISTORY_URL.format(
            settings.uuid, media_id, video_id)

        templateLoader = jinja2.FileSystemLoader(searchpath="./")
        templateEnv = jinja2.Environment(loader=templateLoader)
        template_file = "detail.tpl"
        template = templateEnv.get_template(template_file)
        output = template.render(**content)
        fd = open(fname, 'w')
        fd.write(output)
        fd.close()
        return new_url
예제 #2
0
 def export_html(self, path, override=True):
     prefix = os.environ.get('file_prefix', '')
     new_url = "medias/%s%s.html"%(prefix, self.id)
     fname = os.path.join(path, new_url)
     if override is False and os.path.exists(fname):
         logging.debug("export %s, ignored"%fname)
         return new_url
     self.retrieve()
     try:
         j = json.loads(self.data)
     except:
         self.set_err(ErrCode.DATA_INVALID, "export_html() fail to load "
                      "response data to json")
         return "#None"
     content = {}
     if 'title' not in j:
         self.set_err(ErrCode.DATA_INVALID, "export_html() no title "
                      "field found")
         return "#None"
     content['title'] = j['title']
     content['num'] = len(j['videos'])
     iqiyi_re = re.compile(r'qiyipic')
     picture = j['image_post_url']
     m = iqiyi_re.search(picture)
     if m:
         content['pic'] = dump_pic(picture)
     else:
         content['pic'] = picture
     content['content'] = j['summary']
     content['create_time'] = str(datetime.now())[:19]
     content['actors'] = " | ".join(j['actor'])
     content['category'] = j['category']
     content['tag'] = " | ".join(j['child_category'])
     media_id = j['id']
     if len(j['videos']) == 0:
         self.set_err(ErrCode.DATA_INVALID, "export_html() fail to get video info,"
                      " video number is 0")
         return "#None"
     video_id = j['videos'][0]['id']
     content['history_url'] = settings.HISTORY_URL.format(
         settings.uuid, media_id, video_id)
     
     templateLoader = jinja2.FileSystemLoader(searchpath="./")
     templateEnv = jinja2.Environment(loader=templateLoader)
     template_file = "detail.tpl"
     template = templateEnv.get_template(template_file)
     output = template.render(**content)
     fd = open(fname, 'w')
     fd.write(output)
     fd.close()
     return new_url
예제 #3
0
    def export(self):
        global VIP_TITLE_INDEX
        # if the picture is from iqiyi, save it to local disk
        picture = self.facets[0].pic
        m = iqiyi_re.search(picture)
        title = self.facets[0].title
        alt = title
        if m:
            picture = dump_pic(picture)

        ret, msg = validate_pic(picture)
        if not ret:
            alt += " (no picture load)"

        addtion = self.facets[0].addtion

        # if addtion is empty, just return the poster div html text
        # if not empty, add the addtion information before, the addtion
        # information currently is for VIP dialog exported by related
        # api module, also we need access the dialog name for more than
        # one vip dialog need to support
        if len(addtion) == 0:
            return TileHtmlElement.html_tag.format(top=self.pos[1] * rate,
                                                   left=self.pos[0] * rate,
                                                   width=self.size[1] * rate,
                                                   height=self.size[0] * rate,
                                                   pic=picture,
                                                   title=title,
                                                   alt=alt,
                                                   url=self.facets[0].url,
                                                   vip="")
        else:

            vip_dialog_name = "basicModal%s" % self.facets[0].vip_dialog_name
            return addtion + TileHtmlElement.html_tag.format(
                top=self.pos[1] * rate,
                left=self.pos[0] * rate,
                width=self.size[1] * rate,
                height=self.size[0] * rate,
                pic=picture,
                title=title,
                alt=alt,
                url=self.facets[0].url,
                vip='''data-toggle="modal" data-target="#%s"''' %
                vip_dialog_name)
예제 #4
0
    def export(self):
        global VIP_TITLE_INDEX
        # if the picture is from iqiyi, save it to local disk
        picture = self.facets[0].pic
        m = iqiyi_re.search(picture)
        title = self.facets[0].title
        alt = title
        if m:
            picture = dump_pic(picture)
        
        ret, msg = validate_pic(picture)
        if not ret:
            alt += " (no picture load)"

        addtion = self.facets[0].addtion
        
        
        # if addtion is empty, just return the poster div html text
        # if not empty, add the addtion information before, the addtion
        # information currently is for VIP dialog exported by related
        # api module, also we need access the dialog name for more than
        # one vip dialog need to support
        if len(addtion) == 0:
            return TileHtmlElement.html_tag.format(top=self.pos[1] * rate,
                                                   left=self.pos[0] * rate,
                                                   width=self.size[1] * rate,
                                                   height=self.size[0] * rate,
                                                   pic=picture,
                                                   title=title,
                                                   alt=alt,
                                                   url=self.facets[0].url,
                                                   vip="")
        else:

            vip_dialog_name = "basicModal%s"%self.facets[0].vip_dialog_name
            return addtion + TileHtmlElement.html_tag.format(top=self.pos[1] * rate,
                                                             left=self.pos[0] * rate,
                                                             width=self.size[1] * rate,
                                                             height=self.size[0] * rate,
                                                             pic=picture,
                                                             title=title,
                                                             alt=alt,
                                                             url=self.facets[0].url,
                                                             vip='''data-toggle="modal" data-target="#%s"'''%vip_dialog_name)
예제 #5
0
    def _gen_medias_html(self, path, medias, width, height):
        x = 20
        y = 480
        count_per_line = 7

        xcell = 12
        ycell = 10
        rate = 0.6
        line = '''<div class="poster" style="top:{top};left:{left};position:absolute;z-index:1;visibility:show;"><a href="{detail_link}"><img src="{pic}" title="{title}" alt="{alt}" style="width:100%; height:100%"></img></a></div>'''
        i = 0
        s = ""
        while i < len(medias):
            m = medias[i]
            picture = m['image_icon_url']
            iqiyi_re = re.compile(r'qiyipic')
            if iqiyi_re.search(picture):
                picture = dump_pic(picture)
            title = m['title']
            alt = title
            ret, msg = validate_pic(picture)
            if not ret:
                alt += " (no picture load)"

            yy = (i / count_per_line) * (height + ycell) + y
            xx = (i % count_per_line) * (width + xcell) + x + 10
            ma = MediaApiModule(m['id'])
            # we know the media path is the same level of category
            detail_link = ma.export_html(path, False)
            detail_link = os.path.join('../', detail_link)
            s += line.format(top=yy,
                             left=xx,
                             pic=picture,
                             title=title,
                             width=width * rate,
                             height=height * rate,
                             detail_link=detail_link,
                             alt=alt,
                             description=get_second_title(m['id'], title))
            s += '\n'
            i += 1

        return s
예제 #6
0
 def _gen_medias_html(self, path, medias, width, height):
     x = 20
     y = 480
     count_per_line = 7
     
     xcell = 12
     ycell = 10
     rate = 0.6
     line = '''<div class="poster" style="top:{top};left:{left};position:absolute;z-index:1;visibility:show;"><a href="{detail_link}"><img src="{pic}" title="{title}" alt="{alt}" style="width:100%; height:100%"></img></a></div>'''
     i = 0
     s = ""
     while i < len(medias):
         m = medias[i]
         picture = m['image_icon_url']
         iqiyi_re = re.compile(r'qiyipic')
         if iqiyi_re.search(picture):
             picture = dump_pic(picture)
         title = m['title']
         alt = title
         ret, msg = validate_pic(picture)
         if not ret:
             alt += " (no picture load)"
             
         yy = (i / count_per_line) * (height + ycell) + y
         xx = (i % count_per_line) * (width + xcell) + x + 10
         ma = MediaApiModule(m['id'])
         # we know the media path is the same level of category
         detail_link = ma.export_html(path, False)
         detail_link = os.path.join('../', detail_link)
         s += line.format(top=yy, left=xx, pic=picture,
                          title=title,
                          width=width*rate,
                          height=height*rate,
                          detail_link=detail_link,
                          alt=alt,
                          description=get_second_title(m['id'], title))
         s += '\n'
         i += 1
         
     return s