コード例 #1
0
ファイル: tags.py プロジェクト: outbounder/api-techbrowser
def getTagsForUrl(url):
    try:
        content = resource.get(url).decodeBody().lower()
    except:
        content = ""
    
    soup = BeautifulSoup(content) 
    texts = soup.findAll(text=True)

    def visible(element):
        if element.parent.name in ['style', 'script', '[document]', 'head', 'title']:
            return False
        elif re.match('<!--.*-->', str(element)):
            return False
        return True
    
    visible_texts = filter(visible, texts)
    visibleText = " ".join(visible_texts)
    
    result = getTagsProposalsForText(visibleText)
    
    entry = Entry.all().filter("url =", url).fetch(1)
    if len(entry) > 0:
        entryStableTags = entry[0].tags
        for t in entryStableTags:
            found = False
            name = Tag.get(t).name
            for r in result:
                if name == r:
                    found = True
            if not found:
                result.append(name)
                
    return result
コード例 #2
0
ファイル: notesmd.py プロジェクト: nhrdl/notesMD
 def addTag(self, noteId, strTag):
     count = Tag.select().where(Tag.tag == strTag).count()
     if (count == 0):
         dbTag = Tag()
         dbTag.creationDate = dbTag.modificationDate = datetime.date.today()
         dbTag.tag = strTag
         dbTag.save()
     else:
         dbTag = Tag.get(Tag.tag == strTag)
         
     note = Note.get(Note.id == noteId)
     noteTag = NoteTag()
     noteTag.note = note
     noteTag.tag = dbTag
     noteTag.creationDate = noteTag.modificationDate = datetime.date.today()
     noteTag.save() 
     
     self.view.execute_script("notesMD.tags = " + RuntimeSettings.getTags())
コード例 #3
0
ファイル: notesmd.py プロジェクト: nhrdl/notesMD
 def removeTag(self, noteId, strTag):
     tag = Tag.get(Tag.tag == strTag)
     NoteTag.get(NoteTag.note == noteId, NoteTag.tag == tag.id).delete_instance()