Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

stackexchange api - Watching for new Mathematica questions using Mathematica and the StackOverflow API

Unless Mr.Wizard is on vacation, it is pretty difficult to beat this phenomenon which seems to be gifted with omnipresence and omniscience. How can we outdo him using Mathematica and the StackOverflow API?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Here's a variation on Sjoerd's solution.

The main difference is to use a docked cell instead of a popup dialog. The cell has a link to the new post, as well as a button that will clear the docked cell to the previous state.

The other difference is to use the question ID instead of the title for determining new posts. I know that titles get edited sometimes, so this trigger as a new post in that case.

storedTitle = "";
storedID = 0;
mySOWatchTask = 
  CreateScheduledTask[{lastTitle, 
     lastID} = {"title", 
      "question_id"} /. ("questions" /. 
        Import["http://api.stackoverflow.com/1.1/questions?key=       
         QEpjCjsXYE6s_kZEkFr4Lw&page=1&pagesize=1&sort=creation&
tagged=                mathematica", "JSON"])[[1]];
   If[lastID != storedID,
    storedTitle = lastTitle;
    storedID = lastID;
    SetOptions[$FrontEndSession, 
     DockedCells -> 
      Cell[BoxData[
        ToBoxes[Style[
          With[{dock = Options[$FrontEndSession, DockedCells]}, 
           Grid[{{Button[Style["[CircleTimes]", 16], 
               SetOptions[$FrontEndSession, dock], 
               Appearance -> None], "New StackOverflow question: ", 
              Hyperlink[lastTitle, 
               "http://stackoverflow.com/questions/" <> 
                ToString[lastID]]}}, 
            Alignment -> {{Left, Left, Left}}, 
            ItemSize -> {{2, 14, Scaled[0.7]}}]], 
          FontFamily -> "Times"]]], "DockedCell", 
       Background -> Orange]]; EmitSound[Sound[SoundNote[]]]];, 60];

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...