• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python tag.Tag类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tag.Tag的典型用法代码示例。如果您正苦于以下问题:Python Tag类的具体用法?Python Tag怎么用?Python Tag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Tag类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: save_photo_description

    def save_photo_description(self, user, title, caption, tag_list):
        self.title = title
        self.caption = caption

        i = 0
        tag_list = set([t.strip() for t in tag_list if t.strip() != ''])
        for t in tag_list:
            i += 1  # 序号计数

            # 统计标签
            try:
                tt = Tag.objects.get(name=t)
            except Tag.DoesNotExist:
                tt = Tag(name=t)  # 该标签首次出现,创建
            else:
                tt.used_count += 1  # 该标签已存在,增加使用计数

            tt.save()
            self.tags.add(tt)  # 为照片添加标签,tags为多对多关系

            # 为该用户添加使用的标签
            try:
                usertag = UserTag.objects.get(user=self.owner, tag=tt)
            except UserTag.DoesNotExist:
                usertag = UserTag(user=self.owner, tag=tt)  # 该用户从未使用过该标签,创建
            else:
                usertag.used_count += 1  # 该用户已有该标签,增加使用计数
            usertag.save()

        self.save()  # 保存照片信息
开发者ID:restran,项目名称:green-glow,代码行数:30,代码来源:photo.py


示例2: add_hash

            def add_hash():
                SqlClass.turn_off_commits()
                videos = Video.get_all()
                tags = [video.get_tags() for video in videos]
                # We need to get all the frame info before
                # we erase the video table!
                for tag_ls in tags:
                    for tag in tag_ls:
                        tag._populate_frame_dict()

                for video in videos:
                    if not video.present():
                        self.log.error("Not all videos are present, cannot upgrade database!")
                        return False

                [video.remove() for video in videos]
                Video.remove_table()
                Video.table_setup()
                for i, video in enumerate(videos):
                    video.video_hash = \
                      hash_video(self.get_absolute_path(video.video_path))
                    Video.add(video)
                    for tag in tags[i]:
                        self.log.info("Adding tag %s in video %s" %(tag, video.video_path))
                        Tag.tag_add(tag)

                SqlClass.turn_on_commits()
                self.conn.commit()
                return True
开发者ID:athityakumar,项目名称:software,代码行数:29,代码来源:database.py


示例3: main

def main():
    args = argHandler()
    if args.recursively is None:
        if (args.file is None):
            print "Error: Must especified at least one argument: -f (file)" \
                  + " or -r (folder)"
        else:
            if (checkPath(args.file, 'File')):
                if (isMP3(args.file)):
                    tag = Tag()
                    tag.create(args.file)
                    updateTag(tag, args)
                    tag.updateFile()
                else:
                    print "Error: is not mp3 file"
    else:
        if (checkPath(args.recursively, 'Folder')):
            for root, dirs, files in os.walk(args.recursively, topdown=False):
                for file in files:
                    if (isMP3(file)):
                        tag = Tag()
                        tag.create(os.path.join(root, file))
                        updateTag(tag, args)
                        tag.updateFile()
    print "Done!"
开发者ID:martinweingart,项目名称:tagger,代码行数:25,代码来源:tagger.py


示例4: run

	def run(self):
		n=0
		while True:
			if n%100==0:
				proxy=getProxy(self.proxyid)
				if self.proxyid>0 and proxy is None:
					print("No proxy available! Sleeping...")
					time.sleep(3600)
					continue
				try:
					httpClient=HttpClient(proxy)
					keysv1=conf.getint('default', 'keysv1')
					keyv1=conf.get('keyv1', 'key%d' % randrange(keysv1))
					dbclientv1=DoubanClient(keyv1, httpClient)
					tagClient=Tag(dbclientv1)
					colClient=Collection(dbclientv1)
				except Exception as e: print(e)
			uid=self.queue.get()
			print(self.name, 'is processing', uid)
			try:
				movietags=tagClient.getTagsAll(uid, 'movie')
				musictags=tagClient.getTagsAll(uid, 'music')
				booktags=tagClient.getTagsAll(uid, 'book')
				movies=colClient.getMoviesAll(uid)
				books=colClient.getItemsAll(uid, 'book')
				music=colClient.getItemsAll(uid, 'music')
				dao.saveTC(uid, movietags, musictags, booktags, movies, music, books)
				n+=1
			except Exception as e: print(uid, e)
			self.queue.task_done()
开发者ID:zzjjzzgggg,项目名称:douban-v4,代码行数:30,代码来源:workers.py


示例5: updateFolder

def updateFolder(folder, args):
    for root, dirs, files in os.walk(folder, topdown=False):
        for file in files:
            if (isMP3(file)):
                tag = Tag()
                tag.create(os.path.join(root, file))
                updateTag(tag, args)
                tag.updateFile()
开发者ID:martinweingart,项目名称:tagger,代码行数:8,代码来源:tagger.py


示例6: handle

    def handle(self, *args, **options):
        print("Will delete the table of tags and normal tags, Y/n")
        delete = raw_input()
        if not delete == "Y":
            return

        Tag.delete_all()
        Normal.delete_all()

        self.do_init()
开发者ID:tyrchen,项目名称:kagalaska,代码行数:10,代码来源:initial_db.py


示例7: update_photo_info

    def update_photo_info(self, title, caption, tag_list):
        self.title = title
        self.caption = caption
        tags = self.tags.all()
        # 将该照片的关联标签删除,并更新标签计数,如果为0,就删除标签
        for t in tags:
            self.tags.remove(t)
            self.save()  # 保存照片信息
            t.used_count -= 1

            usertag = UserTag.objects.get(user=self.owner, tag=t)
            usertag.used_count -= 1
            if usertag.used_count <= 0:
                usertag.delete()
            else:
                t.save()

            if t.used_count <= 0:
                t.delete()
            else:
                usertag.save()
        i = 0
        for t in tag_list:
            t = t.strip()  # 去掉两端的空格
            if t == '' or tag_list.index(t) != i:
                continue  # 空字符串不是标签,存在重复,去掉重复的

            i += 1  # 序号计数

            # 统计标签
            try:
                tt = Tag.objects.get(name=t)
            except Tag.DoesNotExist:
                tt = Tag(name=t)  # 该标签首次出现,创建
            else:
                tt.used_count += 1  # 该标签已存在,增加使用计数

            tt.save()
            self.tags.add(tt)  # 为照片添加标签

            # 为该用户添加使用的标签
            try:
                usertag = UserTag.objects.get(user=self.owner, tag=tt)
            except UserTag.DoesNotExist:
                usertag = UserTag(user=self.owner, tag=tt)  # 该用户从未使用过该标签,创建
            else:
                usertag.used_count += 1  # 该用户已有该标签,增加使用计数

            usertag.save()

        self.save()  # 保存照片信息
开发者ID:restran,项目名称:green-glow,代码行数:51,代码来源:photo.py


示例8: __init__

class VersionRequirement:
    def __init__(self, dependence, name, operator, version):
        self.dependence = dependence
        self.name = name
        self.operator = operator
        self.version = version
        self.store_versions()

    def store_versions(self):
        op = self.operator
        if op == "=":
            self.min_version = Tag(self.version)
            self.max_version = Tag(self.version)
        elif op == ">":
            self.min_version = Tag(self.version)
            self.min_version.increment()
            self.max_version = Tag.max_tag()
        elif op == ">=":
            self.min_version = Tag(self.version)
            self.max_version = Tag.max_tag()
        elif op == "<":
            self.min_version = Tag.min_tag()
            self.max_version = Tag(self.version)
            self.max_version.decrement()
        elif op == "<=":
            self.min_version = Tag.min_tag()
            self.max_version = Tag(self.version)
        elif op == "~>":
            version_nums = self.version.split(".")
            length = len(version_nums)
            while len(version_nums) < 3:
                version_nums.append("0")
            version_str = ".".join(version_nums)

            self.min_version = Tag(version_str)
            if length == 1:
                self.max_version = Tag.max_tag()
            else:
                self.max_version = Tag(version_str)
                if length == 2: self.max_version.major_bump()
                elif length == 3: self.max_version.minor_bump()
                self.max_version.decrement()
        else:
            raise Exception("Error: unknown version constraint: %s" % operator)

    def compatible_with(self, other):
        return ((self.min_version <= other.max_version) and
                (self.max_version >= other.min_version))
开发者ID:RSEmail,项目名称:tina,代码行数:48,代码来源:version_requirement.py


示例9: add_tag_by_name

    def add_tag_by_name(self, tag_name, vocab=None, autoflush=True):
        """Add a tag with the given name to this package's tags.

        By default the given tag_name will be searched for among the free tags
        (tags which do not belong to any vocabulary) only. If the optional
        argument `vocab` is given then the named vocab will be searched for the
        tag name instead.

        If no tag with the given name is found, one will be created. If the
        optional argument vocab is given and there is no tag with the given
        name in the given vocabulary, then a new tag will be created and added
        to the vocabulary.

        """
        from tag import Tag
        if not tag_name:
            return
        # Get the named tag.
        tag = Tag.by_name(tag_name, vocab=vocab, autoflush=autoflush)
        if not tag:
            # Tag doesn't exist yet, make a new one.
            if vocab:
                tag = Tag(name=tag_name, vocabulary_id=vocab.id)
            else:
                tag = Tag(name=tag_name)
        assert tag is not None
        self.add_tag(tag)
开发者ID:HatemAlSum,项目名称:ckan,代码行数:27,代码来源:package.py


示例10: __init__

	def __init__(self, element_tag):
		self._tag_name = element_tag.lower()
		self._tag = Tag(element_tag)
		self._attributes = {}
		self._text = ''
		self._sub_elements = []
		self._rand = Rand()
开发者ID:boboguessme,项目名称:cold_fuzzer,代码行数:7,代码来源:element.py


示例11: fromJson

    def fromJson(json_obj):

        ModelValidator.json('event', json_obj)

        event = Event(
            name =json_obj["name"],
            datetime=parser.parse(json_obj["datetime"]),
            venue_id = json_obj["venue_id"],
            creator_id = json_obj["creator_id"],
        )

        #create invitations
        for p in json_obj['participant_ids']:
            user = User.query.get(p)
            if user is not None:
                i = Invitation()
                i.user = user
                event.participant_ids.append(i)

        if 'public' in json_obj:
            event.public = json_obj["public"]

        if 'tags' in json_obj:
            for t in json_obj['tags']:
                tag = Tag.get_or_create(name = t)
                event.tags.append(tag)

        return event
开发者ID:inkrement,项目名称:server,代码行数:28,代码来源:event.py


示例12: tags

    def tags(self):
        """
        A list of ``Tag`` objects that are available in this repo

        Returns
            ``git.Tag[]``
        """
        return Tag.find_all(self)
开发者ID:dvdotsenko,项目名称:ges,代码行数:8,代码来源:repo.py


示例13: create

 def create(cls, delegateable, tag, creator):
     from tag import Tag
     if not isinstance(tag, Tag):
         tag = Tag.find_or_create(tag)
     tagging = Tagging(delegateable, tag, creator)
     meta.Session.add(tagging)
     meta.Session.flush()
     return tagging
开发者ID:AnonOnWarpath,项目名称:adhocracy,代码行数:8,代码来源:tagging.py


示例14: copy_video

    def copy_video(self, vhash, source_db, dest_db, copy_tags=False):
        Video.link_sqlite(source_db)
        v = self.hash_to_vid(vhash)
        self.log.info("Copy video %s" % v)
        video_params = {}
        for k in v.__get_table_keys__():
            if k not in v.ban_keys:
                video_params[k] = getattr(v, k)
        Video.link_sqlite(dest_db)
        new_vid = Video.new(**video_params)

        if copy_tags:
            Tag.link_sqlite(source_db)
            for t in v.get_tags():
                new_tag = self.copy_tag(t, source_db, dest_db, copy_tag_data=True)
                new_tag.set_parent(new_vid)

        return new_vid
开发者ID:athityakumar,项目名称:software,代码行数:18,代码来源:merge.py


示例15: add_tag_by_name

 def add_tag_by_name(self, tagname, autoflush=True):
     from tag import Tag
     if not tagname:
         return
     tag = Tag.by_name(tagname, autoflush=autoflush)
     if not tag:
         tag = Tag(name=tagname)
     if not tag in self.tags:
         self.tags.append(tag)
开发者ID:AdamJensen-dk,项目名称:ckan-drupal,代码行数:9,代码来源:package.py


示例16: __init__

 def __init__(self, path):
     self.path = path
     self.root = Tag('root')
     self.html = ''
     self.tag_stack = [self.root]  # 标签栈, 保存的是未完成解析的tag
     self.symbol_stack = [[-1, '>']]  # 符号栈
     self.last_tag = self.root
     self._get_html()
     self.extract()
开发者ID:lddhbu,项目名称:HTMLParse,代码行数:9,代码来源:parse.py


示例17: zsite_tag_list_by_zsite_id_if_len

def zsite_tag_list_by_zsite_id_if_len(zsite_id):
    tag_id_list = tag_id_list_by_zsite_id(zsite_id)
    tid = zsite_tag_id_list_by_zsite_id(zsite_id)
    r = []
    tid_list = []
    for i, count, t in zip(tag_id_list, zsite_tag_count.get_list(tid), tid):
        if count:
            r.append(i)
            tid_list.append(t)
    return tuple(zip(tid_list, Tag.value_by_id_list(r).itervalues()))
开发者ID:,项目名称:,代码行数:10,代码来源:


示例18: SetTags

  def SetTags(self, tag_list):
    author_tag = Tag.normalise(u"author:%s" % (self.user.username,))
    tags = (set([x for x in tag_list if Map.TAG_RE.search(x)][:5])
            - Map.RESERVED_TAGS)
    old_tags = set(self.tags)
    old_tags.discard(author_tag)
    new_tags = set(tags)

    # Update tag join counts
    # These are used for suggestions, so exclude reserved tags
    old_tagjoins = set(TagJoin.GetPowerset(list(old_tags - Map.RESERVED_TAGS)[:5]))
    new_tagjoins = set(TagJoin.GetPowerset(list(tags)))

    new_tags.update(old_tags.intersection(Map.RESERVED_TAGS))
    new_tags.add(author_tag)

    # Process added tags
    modified_tags = []
    for tag_name in new_tags - old_tags:
      if Tag.normalise(tag_name):
        tag = Tag.get_or_insert_tag(tag_name)
        tag.count += 1
        modified_tags.append(tag)
    # Process removed tags
    for tag_name in old_tags - new_tags:
      if Tag.normalise(tag_name):
        tag = Tag.get_or_insert_tag(tag_name)
        tag.count -= 1
        modified_tags.append(tag)
    if modified_tags:
      db.put(modified_tags)

    # Process modified tagjoins
    TagJoin.update_joins(new_tagjoins, old_tagjoins, 20)

    self.tags = new_tags
    if tag_list:
      self.category = tag_list[0]
    else:
      self.category = None
开发者ID:n-community,项目名称:numa,代码行数:40,代码来源:map.py


示例19: tag_by_po_id

def tag_by_po_id(zsite_id, po_id):
    c = ZsiteTagPo.raw_sql(
        'select zsite_tag_id from zsite_tag_po where zsite_id=%s and po_id=%s',
        zsite_id, po_id
    )
    r = c.fetchone()
    if r:
        zsite_tag_id = r[0]
        tag = ZsiteTag.mc_get(zsite_tag_id)
        tag_id = tag.tag_id
    else:
        return 0, 0, None
    return tag_id, zsite_tag_id, Tag.get(tag_id)
开发者ID:,项目名称:,代码行数:13,代码来源:


示例20: settags

    def settags(self, values):
        if not values:
            return
        if type(values) == type([]):
            tags = values
        else:
            tags = values.split(',')
            
        tags = [tag.strip() for tag in tags]

        if not self.tags:
            removelist = []
            addlist = tags
        else:
            removelist = [n for n in self.tags if n not in tags]
            addlist = [n for n in tags if n not in self.tags]
            
        for v in removelist:
            Tag.remove(v)
        for v in addlist:
            Tag.add(v)
        self.tags = tags
开发者ID:oldhu,项目名称:micolog-oldhu,代码行数:22,代码来源:entry.py



注:本文中的tag.Tag类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tagger.Tagger类代码示例发布时间:2022-05-27
下一篇:
Python log.debug函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap