コード例 #1
0
ファイル: api_module.py プロジェクト: wanziforever/tools
    def _gen_topics_html(self, path, topics, width, height):
        x = 20
        y = 60
        count_per_line = 2
        
        xcell = 10
        ycell = 10
        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(topics):
            t = topics[i]
            picture = t['pics'][0]['url']
            title = t['topicName']
            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
            td = TopicApiModule(t['topicId'])
            # we know the media path is the same level of category
            detail_link = td.export_html(path, False)
            detail_link = os.path.join('../', detail_link)
            s += line.format(top=yy, left=xx, pic=picture,
                             title=title, 
                             detail_link=detail_link,
                             alt=alt)
            s += '\n'
            i += 1
        return s
コード例 #2
0
    def _gen_topics_html(self, path, topics, width, height):
        x = 20
        y = 60
        count_per_line = 2

        xcell = 10
        ycell = 10
        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(topics):
            t = topics[i]
            picture = t['pics'][0]['url']
            title = t['topicName']
            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
            td = TopicApiModule(t['topicId'])
            # we know the media path is the same level of category
            detail_link = td.export_html(path, False)
            detail_link = os.path.join('../', detail_link)
            s += line.format(top=yy,
                             left=xx,
                             pic=picture,
                             title=title,
                             detail_link=detail_link,
                             alt=alt)
            s += '\n'
            i += 1
        return s
コード例 #3
0
ファイル: html_export.py プロジェクト: wanziforever/tools
 def export_multi_facets(self):
     global caro_seq
     caro_seq += 1
     image_list = []
     title_list = []
     alt_list = []
     link_list = []
     for f in self.facets:
         picture = f.pic
         title = f.title
         alt = title
         link =  f.url
         ret, msg = validate_pic(picture)
         if not ret:
             alt += " (no picture loaded)"
         image_list.append(picture)
         title_list.append(title)
         alt_list.append(alt)
         link_list.append(link)
     return gen_caro_html_code(self.pos[1]*rate,
                               self.pos[0]*rate,
                               self.size[1]*rate,
                               self.size[0]*rate,
                               image_list,
                               title_list,
                               link_list,
                               caro_seq)
コード例 #4
0
 def pic_verify(self):
     succ, msg = validate_pic(self.pic)
     if succ is False:
         alarm(ALARM_LEVEL.CRITICAL, ALM_POSTER_IMAGE_GONE,
               "picture of url{url} cannot be loaded, err({err_msg})\n"
               "\nlocation: \n{location}".\
               format(url=self.pic, err_msg=msg,
                      location=settings.show_exam_stack()))
         return False
     return True
コード例 #5
0
 def pic_verify(self):
     succ, msg = validate_pic(self.pic)
     if succ is False:
         alarm(ALARM_LEVEL.CRITICAL, ALM_POSTER_IMAGE_GONE,
               "picture of url{url} cannot be loaded, err({err_msg})\n"
               "\nlocation: \n{location}".\
               format(url=self.pic, err_msg=msg,
                      location=settings.show_exam_stack()))
         return False
     return True
コード例 #6
0
    def verify_response_basic(self):
        j = None
        try:
            j = json.loads(self.data)
        except:
            self.set_err(ErrCode.DATA_INVALID, "fail to load response "
                         "data to json")
            return False
        if not isinstance(j, dict):
            self.set_err(ErrCode.DATA_INVALID, "data should be aa dict type")
            return False
        if 'medias' not in j:
            self.set_err(ErrCode.DATA_INVALID, "no medias tag found")
            return False

        if not 'background' in j:
            self.set_err(ErrCode.DATA_INVALID,
                         "the background image is absent")
            logging.err("the number of the background image of the topic "
                        "%d is absent" % self.id)

        succ, msg = validate_pic(j['background'])
        if succ is False:
            self.set_err(ErrCode.BAD_DETAIL_VIEW_IMAGE, "topic(%s) background "
                         "image cannot be loaded successfully, err(%s)"%\
                         (media['title'], msg))
            logging.error("topic(%s) background "
                         "image cannot be loaded successfully, err(%s)"%\
                         (media['title'], msg))
            return False

        medias = j['medias']
        if len(medias) == 0:
            self.set_err(ErrCode.DATA_INVALID,
                         "the number of media of this topic is 0")
            logging.error("the number of media is 0 for topic %s" % self.id)
            return False

        min_num = 2
        if len(medias) < min_num:
            self.set_err(
                ErrCode.DATA_INVALID,
                "the number of media of this topic is less than "
                "%d, actual %d" % (min_num, len(medias)))
            logging.error("the number of media of topic %s is less than "
                          "%d, actual %d" % (self.id, min_num, len(medias)))
            return False
        logging.debug("topic %s has %s medias found" % (self.id, len(medias)))

        return True
コード例 #7
0
ファイル: api_module.py プロジェクト: wanziforever/tools
    def verify_response_basic(self):
        j = None
        try:
            j = json.loads(self.data)
        except:
            self.set_err(ErrCode.DATA_INVALID, "fail to load response "
                         "data to json")
            return False
        if not isinstance(j, dict):
            self.set_err(ErrCode.DATA_INVALID, "data should be aa dict type")
            return False
        if 'medias' not in j:
            self.set_err(ErrCode.DATA_INVALID, "no medias tag found")
            return False

        if not 'background' in j:
            self.set_err(ErrCode.DATA_INVALID,
                         "the background image is absent")
            logging.err("the number of the background image of the topic "
                        "%d is absent"%self.id)

        succ, msg = validate_pic(j['background'])
        if succ is False:
            self.set_err(ErrCode.BAD_DETAIL_VIEW_IMAGE, "topic(%s) background "
                         "image cannot be loaded successfully, err(%s)"%\
                         (media['title'], msg))
            logging.error("topic(%s) background "
                         "image cannot be loaded successfully, err(%s)"%\
                         (media['title'], msg))
            return False

        medias = j['medias']
        if len(medias) == 0:
            self.set_err(ErrCode.DATA_INVALID,
                         "the number of media of this topic is 0")
            logging.error("the number of media is 0 for topic %s"%self.id)
            return False
        
        min_num = 2
        if len(medias) < min_num:
            self.set_err(ErrCode.DATA_INVALID,
                         "the number of media of this topic is less than "
                         "%d, actual %d"%(min_num, len(medias)))
            logging.error("the number of media of topic %s is less than "
                          "%d, actual %d"%(self.id, min_num, len(medias)))
            return False
        logging.debug("topic %s has %s medias found"%(self.id, len(medias)))
            
        return True
コード例 #8
0
 def export_one_facet(self):
     picture = self.facets[0].pic
     title = self.facets[0].title
     alt = title
     ret, msg = validate_pic(picture)
     if not ret:
         alt += " (no picture loaded)"
     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)
コード例 #9
0
ファイル: html_export.py プロジェクト: wanziforever/tools
 def export_one_facet(self):
     picture = self.facets[0].pic
     title = self.facets[0].title
     alt = title
     ret, msg = validate_pic(picture)
     if not ret:
         alt += " (no picture loaded)"
     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)
コード例 #10
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)
コード例 #11
0
ファイル: html_export3.py プロジェクト: wanziforever/tools
    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)
コード例 #12
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
コード例 #13
0
ファイル: api_module.py プロジェクト: wanziforever/tools
    def _verify_media(self, medias, i):
        media = medias[i]
        if not isinstance(media, dict):
            self.set_err(ErrCode.DATA_INVALID,
                         "%sst media data should be dict type"%i)
            return False
        if 'title' not in media:
            self.set_err(ErrCode.DATA_INVALID,
                         "%sst media data has no title field"%i)
            return False

        if 'image_icon_url' not in media:
            self.set_err(ErrCode.DATA_INVALID, "media has no image field")
            logging.error("cannot load list view image for %s in category %d"%\
                          (media['title'], self.id))
            return False

        succ, msg = validate_pic(media['image_icon_url'])
        if succ is False:
            self.set_err(ErrCode.BAD_LIST_VIEW_IMAGE, "the %sst media(%s) "
                         "has no picture load successfully, err(%s)"%\
                         (i, media['title'], msg))
            logging.error("%sst media(%s) has no picture load successfully, "
                        "err(%s)"%(i, media['title'], msg))
            return False

        m = MediaApiModule(media['id'])
        if not m.verify():
            # because it is a category list view, so the media offline
            # error is not the same level of media view, so just wrap
            # it to a lower level of error
            # merge all the error here to one eror BAD_LIST_VIEW_MEDIA
            for ecode, msgs in m.last_err.items():
                for m in msgs:
                    self.set_err(ErrCode.BAD_LIST_VIEW_MEDIA,
                                 "\nthe %sst item:\n"%i + m)
                    logging.error(m)
            return False
        
        return True
コード例 #14
0
ファイル: api_module.py プロジェクト: wanziforever/tools
 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
コード例 #15
0
    def _verify_media(self, medias, i):
        media = medias[i]
        if not isinstance(media, dict):
            self.set_err(ErrCode.DATA_INVALID,
                         "%sst media data should be dict type" % i)
            return False
        if 'title' not in media:
            self.set_err(ErrCode.DATA_INVALID,
                         "%sst media data has no title field" % i)
            return False

        if 'image_icon_url' not in media:
            self.set_err(ErrCode.DATA_INVALID, "media has no image field")
            logging.error("cannot load list view image for %s in category %d"%\
                          (media['title'], self.id))
            return False

        succ, msg = validate_pic(media['image_icon_url'])
        if succ is False:
            self.set_err(ErrCode.BAD_LIST_VIEW_IMAGE, "the %sst media(%s) "
                         "has no picture load successfully, err(%s)"%\
                         (i, media['title'], msg))
            logging.error("%sst media(%s) has no picture load successfully, "
                          "err(%s)" % (i, media['title'], msg))
            return False

        m = MediaApiModule(media['id'])
        if not m.verify():
            # because it is a category list view, so the media offline
            # error is not the same level of media view, so just wrap
            # it to a lower level of error
            # merge all the error here to one eror BAD_LIST_VIEW_MEDIA
            for ecode, msgs in m.last_err.items():
                for m in msgs:
                    self.set_err(ErrCode.BAD_LIST_VIEW_MEDIA,
                                 "\nthe %sst item:\n" % i + m)
                    logging.error(m)
            return False

        return True
コード例 #16
0
 def export_multi_facets(self):
     global caro_seq
     caro_seq += 1
     image_list = []
     title_list = []
     alt_list = []
     link_list = []
     for f in self.facets:
         picture = f.pic
         title = f.title
         alt = title
         link = f.url
         ret, msg = validate_pic(picture)
         if not ret:
             alt += " (no picture loaded)"
         image_list.append(picture)
         title_list.append(title)
         alt_list.append(alt)
         link_list.append(link)
     return gen_caro_html_code(self.pos[1] * rate, self.pos[0] * rate,
                               self.size[1] * rate, self.size[0] * rate,
                               image_list, title_list, link_list, caro_seq)
コード例 #17
0
 def pic_verify(self):
     succ, msg = validate_pic(self.pic)
     if succ is False:
         om_err_output("Facet::pic_verify() fail to valid pic, %s"%msg)
         return False
     return True