2016-09-19 1 views
0

Comment pouvons-nous utiliser les balises OneNote (comme data-tag='to-do') avec recherche ou filtre dans l'API OneNote. J'ai essayé d'utiliser des opérateurs de fourniture, mais je n'ai trouvé aucun succès.Pouvons-nous rechercher ou filtrer "data-tag = 'to-do'" dans l'API onenote? Si oui, comment pouvons-nous faire cela?

J'ai essayé de cette façon -

$url = "https://www.onenote.com/api/v1.0/me/notes"; 
    //$url .= "/pages?search=hello"; 
    $url .= "/pages?filter=data-tag eq 'to-do'"; 

Je veux rechercher étiquette de données, puis extraire les données des pages OneNote qui contient les données-tag = 'to-do'.

Toute aide est appréciée et merci d'avance.

Répondre

0

Vous devrez parcourir toutes vos pages.

Pour chaque page, vous pouvez récupérer son contenu avec un appel GET-https://www.onenote.com/api/v1.0/me/notes/pages/%s/content?includeIds=true

De là, vous obtenez une chaîne que vous pouvez analyser.

Je vous conseille d'utiliser jsoup.

Avec jsoup vous pouvez alors écrire (en supposant content contient le contenu de votre page):

Document doc = Jsoup.parse(content); 
Elements todos=doc.select("[data-tag^=\"to-do\"]"); 

for(Element todo:todos) { 
    System.out.println(todo.ownText()); 
    } 
0

Malheureusement OneNote API ne supporte pas encore, donc j'ai écrit mon analyseur personnalisé qui extrait des notes avec Data- tags du contenu de la page. Ici, il est:

public class OneNoteParser 
    { 
     static public List<Note> ExtractTaggedNotes(string pageContent, string tag = "*") 
     { 
      List<Note> allNotes = new List<Note>(); 

      string[] dataTagString = { "data-tag=\""}; 

      string[] dirtyNotes = pageContent.Split(dataTagString, StringSplitOptions.RemoveEmptyEntries); 

      //First one in this array can be dropped as it doesn't contain todo 
      for (int i = 1; i < dirtyNotes.Length; i ) 
      { 
       string curStr = dirtyNotes[i]; 
       Note curNote = new Note(); 

       // Firstly we need to extract all the tags from it (sample html: data-tag="to-do:completed,important" ....) 
       string allTags = curStr.Substring(0,curStr.IndexOf("\"")); 

       curNote.Tags = new List<string>(allTags.Split(',')); 

       // Now we have to jump to the next ">" symbol and start finding the text after it 
       curStr = curStr.Substring(curStr.IndexOf(">")); 

       int depth = 1; 
       bool addAllowed = false; 

       for (int j = 0; j < curStr.Length - 1; j ) 
       { 
        // Finding next tag opener "<" symbol 
        if (curStr[j] == '<') 
        { 
         addAllowed = false; 

         // Checking if it is not "</" closer 
         if (curStr[j 1] == '/') 
         { 
          // Means this is a tag closer. Decreasing depth 
          depth--; 
         } 
         else 
         { 
          // Means this is an tag opener. Increasing depth 
          depth ; 
         } 
        } 
        else if (curStr[j] == '>') 
        { 
         addAllowed = true; 

         if (j > 0 && curStr[j - 1] == '/') 
         { 
          // Means this is a tag closer. Decreasing depth 
          depth--; 
         } 
        } 
        else 
        { 
         if (depth < 1) 
         { 
          // Found end of the tag. Saving index and exiting for loop 
          break; 
         } 

         if (addAllowed) 
          curNote.Text = curStr[j]; // Appending letter to string 
        } 
       } 

       // Filtering by tag and adding to final list 
       if (tag == "*" || curNote.Tags.Any(str => str.Contains(tag)))//curNote.Tags.Contains(tag, StringComparer.CurrentCultureIgnoreCase)) 
         allNotes.Add(curNote); 

      } 
      return allNotes; 
     } 
    } 

Et voici la classe Note

public class Note 
    { 
     public string Text; 
     public List<string> Tags; 
     public Note() 
     { 
      Tags = new List<string>(); 
     } 
    } 

Pour extraire todo-s il suffit d'appeler cette fonction:

OneNoteParser.ExtractTaggedNotes(pageContent, "to-do"); 

Aussi, vous pouvez extraire d'autres balises comme ceci:

OneNoteParser.ExtractTaggedNotes(pageContent, "important"); 
OneNoteParser.ExtractTaggedNotes(pageContent, "highlight"); 
//...