示例#1
0
 def __deduplicate_channels(self, channels):
     s = set()
     output_channels = []
     for channel in channels:
         if channel['channel_id'] not in s:
             output_channels.append(channel)
             s.add(channel['channel_id'])
             continue
         msg = "this channel already exists into input channels"
         warn = utils.CacheError(channel_id=channel['channel_id'], msg=msg)
         logging.warning(warn)
     return output_channels
示例#2
0
    def update_failed_channel(self, channel_id):
        """
        This method set field valid as False. If there is not channel_id, then exceptions will be generated

        :param channel_id: failed channel id (str)
        :exception utils.CacheError: it is not found channel id
        """
        conn = sqlite3.connect(self.db_path)
        if not self.__check_exist_channel_id(conn, channel_id):
            raise utils.CacheError(channel_id=channel_id,
                                   msg="not found channel in DB")
        conn.execute(self.__sql_update_failed_channel, (False, channel_id))
        conn.commit()
        conn.close()
示例#3
0
    def update_channel_downloaded(self, channel_id):
        """
        This function process next cases:
            * valid==False, scrapped==False, downloaded==True
        If you want got more information, see c  lass description

        :param channel_id: field downloaded sets as True
        :exception utils.CacheError: it is not found channel id
        """
        conn = sqlite3.connect(self.db_path)
        if not self.__check_exist_channel_id(conn, channel_id):
            raise utils.CacheError(channel_id=channel_id,
                                   msg="not found channel in DB")
        conn.execute(self.__sql_update_downloaded_channel, (True, channel_id))
        conn.commit()
        conn.close()
示例#4
0
    def get_best_channel_id(self):
        """
        This method returns the best channel_id. This method selects all channels except downloaded==True
        or valid==False. All channels ranges by priority. But there are two flags, which ones set additional ranges.
        (see sql-query)

        :return the best channel_id (str) by priority or '' if there are not any actual channels
        :exception utils.CacheError: it is not found any channel id for return
        """
        conn = sqlite3.connect(self.db_path)

        # It uses fetch one instead of top 1 as not all data bases have top directive
        res = conn.execute(self.__sql_get_best_channel).fetchone()
        conn.close()
        if res is None or len(res) == 0:
            raise utils.CacheError(msg="there are not any channels")
        return res[0]