本文整理汇总了Python中tag.Tag类的典型用法代码示例。如果您正苦于以下问题:Python Tag类的具体用法?Python Tag怎么用?Python Tag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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() # 保存照片信息
示例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
示例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!"
示例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()
示例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()
示例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()
示例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() # 保存照片信息
示例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))
示例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)
示例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()
示例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
示例12: tags
def tags(self):
"""
A list of ``Tag`` objects that are available in this repo
Returns
``git.Tag[]``
"""
return Tag.find_all(self)
示例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
示例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
示例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)