Exemple #1
0
	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()
Exemple #2
0
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!"
Exemple #3
0
    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()  # 保存照片信息
Exemple #4
0
            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
Exemple #5
0
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()
Exemple #6
0
    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()
Exemple #7
0
    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()  # 保存照片信息
Exemple #8
0
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))
Exemple #9
0
	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()
Exemple #10
0
    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)
Exemple #11
0
    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
Exemple #12
0
 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
Exemple #13
0
    def tags(self):
        """
        A list of ``Tag`` objects that are available in this repo

        Returns
            ``git.Tag[]``
        """
        return Tag.find_all(self)
Exemple #14
0
class TestTag:

    def setup_class(self):
        self.tag = Tag()

    def test_del_tmp_groups(self):
        # 清理之前自动化创建的标签组
        for group in self.tag.list_tag().json()['tag_group']:
            if 'tmp_group' in group['group_name']:
                self.tag.del_tag(group_ids=[group['group_id']])

    def test_add_tag(self):
        time_now = time.strftime('%Y%m%d%H%M%S', time.localtime())
        group_name = f'tmp_group{time_now}'
        tag = [{
            'name': f'tmp_tag{time_now}',
        }]
        r = self.tag.add_tag(group_name, tag)
        assert r.status_code == 200 and r.json()['errcode'] == 0

    def test_update_tag(self):
        r = self.tag.update_tag(self.tag.tag_id, name='new_tag_name')
        assert r.status_code == 200 and r.json()['errcode'] == 0

    def test_list_tag(self):
        r = self.tag.list_tag()
        assert r.status_code == 200 and r.json()['errcode'] == 0

    def test_del_tag(self):
        group_ids = [self.tag.group_id]
        tag_ids = [self.tag.tag_id]
        r = self.tag.del_tag(group_ids=group_ids, tag_ids=tag_ids)
        assert r.status_code == 200 and r.json()['errcode'] == 0
Exemple #15
0
 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()
Exemple #16
0
 def get_subscription_hashtags_text(self, media):
     self.update_from_server()
     all_tags = Tag.get_all_tags()
     ignored = self.ignored_tags
     for tag in ignored:
         index = all_tags.index(tag)
         if index >= 0:
             del all_tags[index]
     return [t.get_text(self.language[media]) for t in all_tags]
Exemple #17
0
    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
Exemple #18
0
 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)
Exemple #19
0
 def subscription_hashtags(self):
     self.update_from_server()
     all_tags = Tag.get_all_tags()
     ignored = self.ignored_tags
     for tag in ignored:
         index = all_tags.index(tag)
         if index >= 0:
             del all_tags[index]
     return all_tags
Exemple #20
0
    def createDiv(self, T_content, T_id, T_class, val_B, val_U, val_I,
                  T_div_id):
        zag_div = T_div_id.get("1.0", 'end-1c')
        value = T_content.get("1.0", 'end-1c')
        new_id = T_id.get("1.0", 'end-1c')
        new_class = T_class.get("1.0", 'end-1c')
        self.div = Tag('div', value, id_tag=new_id, class_tag=new_class)
        self.div.contents = value
        self.div.id = new_id
        self.div.clas = new_class

        if zag_div == '':
            body.add_tag(self.div)
            print("brak zagniezdzenia")
        else:
            for elem in body.elem_content:
                if elem.id == zag_div:
                    elem.add_elem(self.div)

        if self.val_B == 0:
            self.div.add_style('font-weight', 'normal')
        elif self.val_B == 1:
            self.div.add_style('font-weight', 'bold')

        if self.val_U == 0:
            self.div.add_style('font-style', 'normal')
        elif self.val_U == 1:
            self.div.add_style('font-style', 'italic')

        if self.val_I == 0:
            self.div.add_style('text-decoration', 'none')
        elif self.val_I == 1:
            self.div.add_style('text-decoration', 'underline')

        self.div.add_style('font-size', self.selectedSize.get())
        self.div.add_style('color', self.selectedColor.get())
        self.div.add_style('font-family', self.selectedFamily.get())
        self.div.add_style('text-align', self.selectedAlign.get())
        self.div.add_style('padding-top', self.selectedTop_P.get())
        self.div.add_style('padding-right', self.selectedRight_P.get())
        self.div.add_style('padding-left', self.selectedLeft_P.get())
        self.div.add_style('padding-bottom', self.selectedBottom_P.get())
        style.add_elem(self.div)
        print("Wykonano funkcje createDiv")
Exemple #21
0
 def get_tag(self, name):
     """
     Returns a Tag for the passed name, associated with this API object. If you know the count value for this tag,
     pass it to update the object. There is no way to query the count directly from the API, but it can be retrieved
     from other calls such as 'artist', however.
     """
     if name in self.cached_tags.keys():
         return self.cached_tags[name]
     else:
         return Tag(name, self)
Exemple #22
0
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()))
Exemple #23
0
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()))
Exemple #24
0
def show_tags():
    tags = Tag.select()
    tags_html = '\n'.join(
        list(
            map(lambda x: "<a href=\"/tags/%s\">%s</a><br>" % (x.name, x.name),
                tags)))
    form_html = "<form action=\"/tags\" method=\"POST\"><label>Enter a tag: </label><input name=\"tag-name\"></form>"
    #embed()
    return "<div><h1>The Ultimate Tag Manager</h1><h1>Tags</h1><a href='/about/'>ABOUT</a></div><img src=\"%s\" style=\"width:300px\"><div>%s</div><div>%s</div>" % (
        cfg['awesome_image'], tags_html, form_html)
Exemple #25
0
def index(q):
    response.content_type = 'application/json'
    tags = Tag().search_tags(graph_db, q)

    tagArray = []
    # build array
    for t in tags:
        tagArray.append({"name": t.name, "id": t.id, "label": t.label})

    return dumps(tagArray)
Exemple #26
0
def process_brown():
    """Read, convert and save the Brown corpus"""
    tags = []
    logging.info("Reading Brown corpus....")
    for word, tag in nltk.corpus.brown.tagged_words(tagset="universal"):
        t = Tag(word, tag)
        tags.append(t)
    logging.info("Saving....")
    with open("Data/brown.pkl", "w") as fout:
        pickle.dump(tags, fout, pickle.HIGHEST_PROTOCOL)
Exemple #27
0
 def __init__(self, queue):
     self.setTitle(self.TITLE)
     self.queue = queue
     self.settings = []
     for setting in self.SETTINGS:
         self.settings.append(setting())
     #self.scrollbar = scrollbarControl(Tag('onright',9000),Tag('posx',1060),Tag('posy',60),Tag('width',25),Tag('height',530),Tag('visible','Container(9000).HasFocus(%d)'%self.Menucategory.getId()),Tag('showonepage','false'))
     self.category = GroupListControl(
         Tag('onleft', 9000),
         Tag('onright', 9000),
         Tag('itemgap', -1),
         Tag('visible',
             'Container(9000).HasFocus(%d)' % self.Menucategory.getId()),
         defaultSKin=False)
     #self.scrollbar.setTag(Tag('onleft',self.category.getId()))
     for setting in self.settings:
         setting.addQueue(self.queue)
         self.category.addControl(setting.getControl())
     self.onInit()
 def delete_tag(media, user_id, code):
     try:
         user = User(media=media, user_id=user_id)
     except UserNotFound:
         new_message = Message(user_id,
                               text=load_text(
                                   TextLabels.MODERATION_UNREGISTERED,
                                   media=media),
                               marks=[MessageMarks.UNREGISTERED])
         response = {'send': list([new_message])}
         return response
     if not user.is_admin:
         new_message = Message(user_id,
                               text=load_text(
                                   TextLabels.MODERATION_ACCESS_DENIED,
                                   media=media,
                                   language=user.language[media]),
                               marks=[MessageMarks.NO_ACCESS])
         response = {'send': list([new_message])}
         return response
     if not code:
         new_message = Message(user_id,
                               text=load_text(
                                   TextLabels.WRONG_COMMAND_SIGNATURE,
                                   media=media))
         response = {'send': list([new_message])}
         return response
     try:
         tag = Tag(code)
     except TagNotFound:
         message_text = load_text(TextLabels.MODERATION_WRONG_TAG_CODE,
                                  media=media)
     else:
         tag.delete()
         message_text = load_text(TextLabels.MODERATION_TAG_DELETED,
                                  media=media).format(tag=tag.code)
     if media == Media.TELEGRAM:
         message_text = message_text.replace('_', '\_')
     new_message = Message(user_id, text=message_text)
     response = {'send': list([new_message])}
     return response
Exemple #29
0
class AssetTags():
    def __init__(self, excel_file, index_of_header, out_pdf_file):
        self.__header, self.__datas = self.__loadfile(excel_file,
                                                      index_of_header)
        self.tag = Tag(out_pdf_file)

    @staticmethod
    def __loadfile(excel_, header_at_row):
        """参数:excel文件;表头所在的行数
           返回值:表头内容(列表);excel内容(字典)
        """
        wb = load_workbook(excel_, read_only=True)
        st = wb.active
        header = []
        data = {}

        for i in range(1, st.max_column + 1):
            header.append(st.cell(row=header_at_row, column=i).value)

        for i, row in enumerate(st.rows):
            temp_dict = {}
            for j, cell in enumerate(row):
                if isinstance(cell.value, datetime.datetime):
                    temp_dict[header[j]] = str(cell.value)[:-8]
                elif cell.value is None:
                    temp_dict[header[j]] = ''
                else:
                    temp_dict[header[j]] = cell.value
            data[i] = temp_dict
        return header, data

    def create_page(self, header=None, _fontsize=7):
        if header is None: header = self.__header

        for i, d in enumerate(self.__datas):
            #因为是字典,所以d的值为与i的值一样

            self.tag.addpage(header, self.__datas[i], _fontsize)

    def save(self):
        self.tag.build()
Exemple #30
0
def phase2(ref,bitFlip,magnitude):
    rRef = []
    for sign in ref:
        ixS = sign.getStart()
        ixE = sign.getEnd()
        if(ixE - ixS > 1):  #we kunnen geen gemiddelde nemen van 1 punt
            mu = statistics.mean(bitFlip[ixS : ixE])
            std = statistics.stdev(bitFlip[ixS : ixE])
        else:
            mu = bitFlip[ixS : ixE]
            std = bitFlip[ixS : ixE]
        if magnitude[ixE] == 0 and matchCounter(bitFlip[ixS :ixE]):
            tag = Tag(ixS,ixE, "COUNTER")
            rRef.append(tag)
        elif ((bitFlip[ixS:ixE] == 0) and ((0.5-std) <= mu ) and (mu <= (0.5 + std))):
            tag = Tag(ixS, ixE, "CRC")
            rRef.append(tag)
        else:
            tag = Tag(ixS, ixE, "PYSH")
            rRef.append(tag)
    return rRef
Exemple #31
0
 def __get_users_with_tagged_messages_from_db(self, tags):
     with self.__driver.session() as session:
         tags = tags.split(", ")
         for tag in tags:
             if not Tag.has_member(tag):
                 raise ValueError(f"Tag: {tag} doesnt exist")
         query = "MATCH (u:user)-[r:messages]-() WHERE"
         for tag in tags:
             query += f" \'{tag}\' IN r.tags AND"
         # removing last AND
         query = query[:-3] + "RETURN u"
         return session.run(query)
Exemple #32
0
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)
Exemple #33
0
  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
Exemple #34
0
def parse_docstring(docstring, context):
    """
    Parses parameters, thrown exception types, return values, 
    and description from the docstring
    @param docstring the docstring to parse data from
    @param context the function or class that the docstring belongs to, used for errors
    @return a dict with keys from docstring tags
    """
    parsed = { 'description' : '' }
    lines = docstring.splitlines()
    i = 0
    while i < len(lines) and not lines[i].startswith('@'):
        if len(lines[i]) == 0:
            parsed['description'] += '  \n'
        else:
            parsed['description'] += lines[i].strip() + ' '
        i += 1
    curr = ''
    for line in lines[i:]:
        line = line.strip()
        if len(line) == 0: continue

        if line.startswith('@'):
            if curr != '':
                collection, result = Tag.parse(curr)
                if result is not None:
                    if collection not in parsed:
                        parsed[collection] = []
                    parsed[collection].append(result)
            curr = line
        else:
            curr += ' ' + line
    if curr != '':
        collection, result = Tag.parse(curr)
        if result is not None:
            if collection not in parsed:
                parsed[collection] = []
            parsed[collection].append(result)
    return parsed
Exemple #35
0
    def update_details(self, event):
        ind = event.GetIndex()
        item = self.allTags_list_ctrl.GetItem(ind, 0)
        self.headline.SetLabelText(item.GetText())

        row_tag = self.allTags_list_ctrl.get_row_object(ind)

        linkedEntries = CampaignLogReader(self.data).createLinks(row_tag)
        #linkedEntries = CampaignLogReader(self.data).createLinks(self.tagsInTable[ind])
        #self.linkedPostsInTable = []

        self.linkedTags_list_ctrl.empty_table()

        index = 0
        for entry in linkedEntries:
            entryAsTag = Tag(entry)
            entryAsTag.count = len(linkedEntries[entry])

            #self.linkedPostsInTable.append(linkedEntries[entry])
            self.linkedTags_list_ctrl.add_row(index, entryAsTag, linkedEntries[entry])

            index += 1
Exemple #36
0
    def do_init(self):
        file = open(self.file_path, "r")
        lines = file.readlines()
        file.close()

        for line in lines[1:]:
            info = line.decode("utf-8")[:-1]
            tag_name, score, parents_str, equal_to, items_str = info.split("\t")
            print(tag_name)
            score = 1.0
            items = []
            parents = parents_str.split(",")

            for item in items_str.split(","):
                name, class_name = item.split("__")
                if class_name == "NORMAL":
                    print("Save normal tag %s" % name)
                    n = Normal(slug=name, score=score)
                    n.save()
                items.append({"slug": name, "class": class_name})
            tag = Tag(name=tag_name, score=score, parents=parents, equal_to=equal_to, items=items)
            tag.save()
Exemple #37
0
    def InitById(self, identifier):

        cur = self.connection.cursor(
            cursor_factory=psycopg2.extras.RealDictCursor)

        q = '''select string_agg(s.name,',') as size, array_agg(s.id) as size_id, p.*, c.name as category from "Product" p 
                inner join "Category" c on c.id = p.category_id 
                inner join "Product_Size" ps on ps.product_sku = p.sku
                inner join "Size" s on s.id = ps.size_id
                where p.id = %(id)s group by p.id, c.name limit 1'''
        p = {"id": identifier}
        try:
            cur.execute(q, p)
            producto = cur.fetchone()

            # print producto

            producto["tags"] = []

            tag = Tag()
            response = tag.GetTagsByProductId(identifier)

            if "success" in response:
                tags = response["success"]
                for t in tags:
                    producto["tags"].append(t["tag_id"])

                # print producto

            # else:
            #   print response["error"]

            if cur.rowcount > 0:
                return self.ShowSuccessMessage(producto)
            else:
                return self.ShowError("product cannot be initialized")
        except Exception, e:
            return self.ShowError(
                "product cannot be initialized, error: {}".format(str(e)))
Exemple #38
0
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)
Exemple #39
0
    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
Exemple #40
0
    def parse_tag(self, tagtype, r):
        target = r.next()

        if tagtype in (0x10, 0x20):
            sens_res = (r.next() << 8) + r.next()
            sel_res = r.next()

            uidlen = r.next()
            uid = ''.join('%02x' % r.next() for i in range(uidlen))

            tag = Tag(self, target, sens_res, sel_res)
            tag.uid = uid

            if tagtype == 0x20:
                atslen = r.next()
                ats = [r.next() for i in range(atslen - 1)]
                tag.ats = ats

        elif tagtype == 0x23:
            atqb = [r.next() for i in range(12)]

            arlen = r.next()
            ar = [r.next() for i in range(arlen)]

        elif tagtype == 0x11:
            prlen = r.next()
            pol_res = [r.next() for i in range(prlen - 1)]
            p = iter(pol_res)

            resp_code = p.next()
            uid = ''.join('%02x' % p.next() for i in range(8))
            print uid

        elif tagtype == 0x4:
            atqa = (r.next() << 8) + r.next()
            uid = ''.join('%02x' % r.next() for i in range(4))

        return tag
    def parse_tag(self, tagtype, r):
        target = r.next()

        if tagtype in (0x10, 0x20):
            sens_res = (r.next() << 8) + r.next()
            sel_res = r.next()

            uidlen = r.next()
            uid = ''.join('%02x' % r.next() for i in range(uidlen))

            tag = Tag(self, target, sens_res, sel_res)
            tag.uid = uid

            if tagtype == 0x20:
                atslen = r.next()
                ats = [r.next() for i in range(atslen - 1)]
                tag.ats = ats

        elif tagtype == 0x23:
            atqb = [r.next() for i in range(12)]

            arlen = r.next()
            ar = [r.next() for i in range(arlen)]

        elif tagtype == 0x11:
            prlen = r.next()
            pol_res = [r.next() for i in range(prlen - 1)]
            p = iter(pol_res)

            resp_code = p.next()
            uid = ''.join('%02x' % p.next() for i in range(8))
            print uid

        elif tagtype == 0x4:
            atqa = (r.next() << 8) + r.next()
            uid = ''.join('%02x' % r.next() for i in range(4))

        return tag
Exemple #42
0
 def interpret_conll(path):
     """
     Read a CONLL file line-by-line and export the tags
     :param path: The path of the file
     :return: A list of Tag objects.
     """
     logging.info("Reading %s...", path)
     ret = []
     tweebo = [
         'N', 'O', '^', 'S', 'Z', 'V', 'L', 'M', 'A', 'R', '!', 'D', 'P',
         '&', 'T', 'X', 'Y', '#', '@', '~', 'U', 'E', '$', ',', 'G'
     ]
     ref = [u'NOUN', u'PRON', 'NOUN', 'DET', 'NOUN', 'VERB', '']
     tagmap = {
         'N': u'NOUN',
         'O': u'PRON',
         '^': u'NOUN',
         'S': u'X',
         'Z': u'NOUN',
         'V': u'VERB',
         'L': u'PRON',
         'M': u'NOUN',
         'A': u'ADJ',
         'R': u'ADV',
         '!': u'.',
         'D': u'DET',
         'P': u'CONJ',
         '&': u'CONJ',
         'T': u'PRT',
         'X': u'DET',
         'Y': u'DET',
         '#': u'X',
         '@': u'NOUN',
         '~': u'X',
         'U': u'X',
         'E': u'.',
         '$': u'NUM',
         ',': u'.',
         'G': u'X'
     }
     with open(path, 'r') as fp:
         for line in fp:
             line = line.strip()
             if len(line) == 0:
                 continue
             line = line.split()
             word, raw = line
             t = Tag(word, tagmap[raw])
             ret.append(t)
     return ret
Exemple #43
0
def get_tag_of_repo(repo):
    tags = repo.tags
    if len(tags) is 0:
        return None

    tag_list = []
    for tag in tags:
        try:
            tag_list.append(Tag(str(tag)))
        except Exception:
            pass

    tag_list.sort()
    return tag_list[-1]
Exemple #44
0
 def post(self):
     self.response.headers.add_header("Access-Control-Allow-Origin", "http://www.jonathonduerig.com");
     postid = self.request.get("postid")
     userid = self.request.get("userid")
     posts = []
     followed = []
     if postid:
         query = Post.all()
         query.filter("postid = ", postid)
         posts = query.fetch(1000)
     elif userid:
         query = Stream.all()
         query.filter("userid = ", userid)
         query.order("-created")
         posts = query.fetch(30)
         query = Relation.all()
         query.filter("follower = ", userid)
         followed = query.fetch(1000)
     resultList = []
     for p in posts:
         resultTags = []
         postkey = ""
         outPostid = ""
         if postid:
             postkey = p.key()
             outPostid = postid
         else:
             postkey = p.postkey.key()
             outPostid = p.postkey.postid
         query = Tag.all()
         query.filter("postkey = ", postkey)
         tags = query.fetch(1000)
         for t in tags:
           found = False
           for f in followed:
             if t.userid == f.user:
               found = True
               break
             pass
           if found or postid:
             tag = {'user': t.userid,
                    'key': t.tag_key,
                    'value': t.tag_value}
             resultTags.append(tag)
           pass
         resultList.append({'postid': outPostid, 'post': p.post,
                            'tags': resultTags})
     resultStr = json.dumps(resultList, sort_keys=True,
                            indent=2)
     self.response.out.write(resultStr)
def print_outfit_tags(opt_sim: OptionalSimInfoParam = None, _connection=None):
    sim_info = get_optional_target(opt_sim,
                                   target_type=OptionalSimInfoParam,
                                   _connection=_connection)
    (current_outfit_category,
     current_outfit_index) = sim_info.get_current_outfit()
    tag_values = set().union(
        *get_tags_from_outfit(sim_info._base, current_outfit_category,
                              current_outfit_index).values())
    output = sims4.commands.Output(_connection)
    tag_names = [Tag(tag_value).name for tag_value in tag_values]
    tag_names.sort()
    for tag in tag_names:
        output(tag)
Exemple #46
0
 def onInit(self):
     self.setTag(
         Tag('height',
             '%d' % (self.getTag('height').getValue()['value'] + 5)))
     self.setTag(Tag('font', 'font13_title'))
     self.setTag(Tag('textcolor', 'blue'))
     self.setTag(Tag('shadowcolor', 'black'))
     self.setTag(Tag('align', 'left'))
     self.setTag(Tag('aligny', 'center'))
 def get_tag_info(media, user_id, code):
     try:
         user = User(media=media, user_id=user_id)
     except UserNotFound:
         new_message = Message(user_id,
                               text=load_text(
                                   TextLabels.MODERATION_UNREGISTERED,
                                   media=media),
                               marks=[MessageMarks.UNREGISTERED])
         response = {'send': list([new_message])}
         return response
     if not user.is_admin:
         new_message = Message(user_id,
                               text=load_text(
                                   TextLabels.MODERATION_ACCESS_DENIED,
                                   media=media,
                                   language=user.language[media]),
                               marks=[MessageMarks.NO_ACCESS])
         response = {'send': list([new_message])}
         return response
     if not code:
         new_message = Message(user_id,
                               text=load_text(
                                   TextLabels.WRONG_COMMAND_SIGNATURE,
                                   media=media))
         response = {'send': list([new_message])}
         return response
     try:
         tag = Tag(code=code)
     except TagNotFound:
         new_message = Message(user_id,
                               text=load_text(
                                   TextLabels.MODERATION_WRONG_TAG_CODE,
                                   media=media))
         response = {'send': list([new_message])}
         return response
     marks = {True: 'да', False: 'нет'}
     message_text = load_text(TextLabels.MODERATION_GET_TAG_INFO,
                              media=media)
     lang_args = {l.name.lower(): tag.text[l] for l in Languages}
     print(lang_args)
     message_text = message_text.format(code=tag.code,
                                        is_shown=marks[tag.is_shown],
                                        **lang_args)
     if media == Media.TELEGRAM:
         message_text = message_text.replace('_', '\_')
     new_message = Message(user_id, text=message_text)
     response = {'send': list([new_message])}
     return response
Exemple #48
0
    def get_tag_from_message(self, message, tag_func):
        date = datetime.fromtimestamp(message.date)
        chat_id = message.chat_id
        user = message.user

        chat = self.mapper.get_chat_by_id(chat_id)
        if chat:
            for t in chat.tags:
                d = datetime.fromtimestamp(t.date)

                if t.user.id == user.id and (message.date - t.date) <= 5 * 60:
                    username = t.user.pretty_print()
                    raise UserTagLimitException("User '%s' is submitting too rapidly" % username)
        text = tag_func(message.text)
        return Tag(text=text, user=user, date=message.date)
Exemple #49
0
 def post(self):
     self.response.headers.add_header("Access-Control-Allow-Origin", "http://www.jonathonduerig.com");
     postid = self.request.get("postid")
     post = self.request.get("post")
     user = self.request.get("user")
     key = self.request.get("key")
     value = self.request.get("value")
     query = Post.all()
     query.filter("postid = ", postid)
     postResult = query.fetch(1000)
     post = Post(postid=postid, post=post)
     if len(postResult) > 0:
         post = postResult[0]
     else:
         post.put()
     tag = Tag(userid=user, postkey=post.key(), tag_key=key, tag_value=value)
     tag.put()
     query = Relation.all()
     query.filter("user = "******"Tagged post " + postid + " with " + user + ":" +
                             key + "=" + value)
Exemple #50
0
 def revert_object_actions(cls):
     if not cls._obj_tag_id_to_count:
         return
     zone = services.current_zone()
     for (obj_tag_id, obj_count) in cls._obj_tag_id_to_count.items():
         if obj_count != 0:
             for action in cls.object_tag_to_actions[Tag(obj_tag_id)]:
                 success = action.revert(obj_count)
                 if not success:
                     continue
                 if action.action_type == ZoneModifierFromObjectsActionType.STATISTIC_CHANGE:
                     zone.zone_architectural_stat_effects[
                         action.stat.guid64] -= action.get_value(obj_count)
     cls._on_build_objects_environment_score_update()
     cls._obj_tag_id_to_count = None
Exemple #51
0
def readTags(oAuth) -> List[Tag]:
    try:
        with open(FileConstants.TAGS, "r") as f:
            tagsJson = f.read()
        tags = json.loads(tagsJson)
        tagList = [
            Tag(None, t["id"], t["isAuto"], t["localizationNames"],
                t["isActive"]) for t in tags
        ]
        return sorted(tagList,
                      key=lambda x: x.localizationNames["en-us"].casefold())
    except JSONDecodeError:
        return updateTwitchTags(oAuth, [], True)
    except FileNotFoundError:
        return updateTwitchTags(oAuth, [], True)
Exemple #52
0
    def InitBySku(self, sku):

        cur = self.connection.cursor(
            cursor_factory=psycopg2.extras.RealDictCursor)

        q = '''select string_agg(s.name,',') as size, array_agg(s.id) as size_id, p.*, c.name as category from "Product" p 
                inner join "Category" c on c.id = p.category_id 
                inner join "Product_Size" ps on ps.product_sku = p.sku
                inner join "Size" s on s.id = ps.size_id
                where p.sku = %(sku)s group by p.id, c.name limit 1'''
        p = {"sku": sku}
        try:

            # print cur.mogrify(q,p)

            cur.execute(q, p)
            producto = cur.fetchone()

            producto["tags"] = []

            tag = Tag()
            response = tag.GetTagsByProductId(producto["id"])

            if "success" in response:
                tags = response["success"]
                for t in tags:
                    producto["tags"].append(t["tag_id"])

            if cur.rowcount > 0:
                return self.ShowSuccessMessage(producto)
            else:
                return self.ShowError(
                    "product with sku {} not found".format(sku))
        except Exception, e:
            return self.ShowError(
                "product cannot be initialized by sku, {}".format(str(e)))
Exemple #53
0
    def test_html_string_parsing(self):
        html = """
                <html>
                    <body>
                        <p>This is a p tag</p>
                    </body>
                </html>
               """
        root = Tag("html")
        body = Tag("body")
        body.add_child(Tag("p"))
        root.add_child(body)
        test_dom = Dom(root=root)

        parser = Parser(html)
        parsed_dom = parser.parse_html()
        parsed_tags = parsed_dom.get_tags(parsed_dom.root)
        expected_tags = test_dom.get_tags(test_dom.root)
        self.assertEquals(len(expected_tags), len(parsed_tags))
        for i, tag in enumerate(expected_tags):
            self.assertEquals(tag.name, parsed_tags[i].name)
Exemple #54
0
    def bonusFindOpeningTags(output):
        tag_list = []
        tag = False
        tag_name = ''
        for i in range(0, len(output)):
            if tag is False:
                if output[i] == '<' and output[i + 1] != '/':
                    tag = True
            else:
                tag_name += output[i]
                if output[i + 1] == '>':
                    tag_list.append(Tag(i, i + len(tag_name), tag_name))
                    tag = False
                    tag_name = ''

        return tag_list
Exemple #55
0
  def addRelation(self, follower, target, existing):
    found = False
    for cur in existing:
      if follower == cur.follower and target == cur.user:
        found = True
        break
      pass
    if not found:
      relation = Relation(follower=follower, user=target)
      relation.put()

      query = Tag.all()
      query.filter("userid = ", target)
      tags = query.fetch(1000)
      for tag in tags:
        tag.addToStream(follower)
Exemple #56
0
    def get_tag(self, callback):
        tag_type = TagType.CLASSIC1K
        rands = []
        memory = Tag.generate_1k()

        ar = self._ar
        for d in ar:
            if d.get('entry','') == 'tag':
                rands = d.get('rands', [])
                tp = d.get('type', '')
                if tp == 'ULTRALIGHT':
                    tag_type = TagType.ULTRALIGHT
                memory = d.get('mem', [])
                break

        return Tag(callback, tag_type, memory, rands)
Exemple #57
0
def extractInfoAboutScanFor(scanData, typeOfInfo, params):
	tagINDb = TagINDBInterface()
	scan = getScanRank(scanData)
	fingerPrints = tagINDb.findRelaventFingerPrints(scanData)
	fpDistances = {}
	if typeOfInfo == 'tags' or typeOfInfo == 'all':
		tagsList = {}
	if typeOfInfo == 'location' or typeOfInfo == 'all':
		fpLocation = {}
		
	for fId in fingerPrints:
		fingerPrint = fingerPrintStrengthToRank(tagINDb.getFingerPrintDetails(fId))
		fpDistances[fId] = findDistanceBetweenFingerPrintAndScan(scan, fingerPrint)
		if typeOfInfo == 'location' or typeOfInfo == 'all':
			fpLocation[fId] = tagINDb.getLocationForFingerPrint(fId)
			
		if typeOfInfo == 'tags' or typeOfInfo == 'all':
			currentTags = tagINDb.getTagsForFingerprint(fId)
			for currentTag in currentTags:
				currentTag = currentTag[0]
				if tagsList.has_key(currentTag):
					t = tagsList[currentTag]
				else:
					t = Tag()
					t.setValue(currentTag)
					tagsList[currentTag] = t
				t.addCount()
				t.addDistance(fpDistances[fId])
				
				
	#normalize the distances
#	allDistances = fpDistances.values()
#	for fId, distance in fpDistances.iteritems():
#		fpDistances[fId] = normalize2range(distance, allDistances, 1.0, 0.1)

	print "Distances:", fpDistances
		
	if typeOfInfo == 'tags':
		return (tagsList)
	elif typeOfInfo == 'location':
		return (fingerPrints, fpDistances, fpLocation)
Exemple #58
0
def zsite_tag_new_by_tag_id(po, tag_id=1):
    if not Tag.get(tag_id):
        tag_id = 1
    zsite_id = po.user_id
    po_id = po.id
    po_cid = po.cid

    if tag_id == 1: #初始化
        zsite_tag_id_list_with_init(zsite_id)

    id = zsite_tag_new_by_zsite_id_tag_id(zsite_id, tag_id)
    tag_po = ZsiteTagPo.get_or_create(
        po_id=po_id,
        zsite_id=zsite_id,
        cid=po_cid
    )

    pre_tag_id = tag_po.zsite_tag_id
    tag_po.zsite_tag_id = id
    tag_po.save()

    mc_tag_by_po_id.delete('%s_%s'%(zsite_id, po_id))

    from model.po_prev_next import mc_flush
    tag_po_id = tag_po.id

    if pre_tag_id:
        mc_po_id_list_by_zsite_tag_id.delete(pre_tag_id)
        zsite_tag_cid_count.delete(pre_tag_id, po_cid)
        mc_po_id_list_by_zsite_tag_id_cid.delete('%s_%s'%(pre_tag_id, po_cid))
        mc_flush(po, zsite_id, pre_tag_id)

    mc_po_id_list_by_zsite_tag_id.delete(id)
    mc_po_id_list_by_zsite_tag_id_cid.delete('%s_%s'%(id, po_cid))
    zsite_tag_cid_count.delete(id, po_cid)
    mc_flush(po, zsite_id, id)
Exemple #59
0
    def test_html_string_parsing(self):
        html = """
                <html>
                    <body>
                        <p>This is a p tag</p>
                    </body>
                </html>
               """
        root = Tag("html")
        body = Tag("body")
        body.add_child(Tag("p"))
        root.add_child(body)
        test_dom = Dom(root=root)

        parser = Parser(html)
        parsed_dom = parser.parse_html()
        parsed_tags = parsed_dom.get_tags(parsed_dom.root)
        expected_tags = test_dom.get_tags(test_dom.root)
        self.assertEquals(len(expected_tags), len(parsed_tags))
        for i, tag in enumerate(expected_tags):
            self.assertEquals(tag.name, parsed_tags[i].name)
Exemple #60
0
 def get_tags(self):
     return Tag.get_all(filter_str="WHERE vid=%d" % self.id)