Example #1
0
    def get_photo_by_url(self, url):
        """
        根据 url 从数据库表 bai_photo 里取一行(python会自动处理成字典类型),转换成程序中的一篇 photo
        :param url: 一个 key, 编码为 unicode
        :return:  Photo 类的一个实例
        """
        sql = "select * from bai_photo where url='{0}'".format(url)

        CrawlerLogger.logger.info('get photo SQL: {0}\n'.format(sql))
        MysqlLogger.logger.info('get photo SQL: {0}\n'.format(sql))
        photo_record = self.db.get(sql)  # 字典, get 方法会判断是不是有重复的,有重复的会报错
        if photo_record:
            return Photo.to_photo(
                photo_record
            )  # 这里其实不用 return 实例吧?return true 给 is_exist 判断就行了吧?
        return None