SHARE
TWEET

Journal entry for DEVONthink 3 (updated)

rfog Jun 7th, 2019 (edited) 141 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (*
  2.     Based on script by Chuck Lane October 2, 2013
  3.     Updated and optimized for DEVONthink 3 by Christian Grunenberg April 30, 2019
  4.     Some changes by RFOG to set news to Inoreader Favorites and put the journal in a specific database, June 7, 2019
  5.     June 8, 2019: Some bug fixing when Inoreader has no favs.
  6. *)
  7.  
  8. property headerColor : {40000, 20000, 0}
  9. property blackColor : {0, 0, 0}
  10. property dateColor : {30000, 30000, 30000}
  11. property numHeadlines : 10
  12. property quoteOfDayUrl : "feed://feeds.feedburner.com/quotationspage/qotd"
  13. property inoreaderUrl : "feed://www.inoreader.com/stream/user/1005968576/tag/user-favorites"
  14. property genericNewsUrl : "feed://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml"
  15. property desiredDatabase : "~/Databases/RFOG.dtBase2"
  16.  
  17. set theDate to current date
  18.  
  19. -- TIME FORMAT: Strip out the seconds but keep the AM/PM indicator
  20. set theTime to time string of theDate
  21. if (theTime contains "AM" or theTime contains "PM") then
  22.     if character 5 of theTime is ":" then
  23.         set theTime to (characters 1 through 4 of theTime) & (characters 8 through 10 of theTime) as string
  24.     else
  25.         set theTime to (characters 1 through 5 of theTime) & (characters 9 through 11 of theTime) as string
  26.     end if
  27. else if character 5 of theTime is ":" then
  28.     set theTime to (characters 1 through 4 of theTime)
  29. else
  30.     set theTime to (characters 1 through 5 of theTime)
  31. end if
  32.  
  33. -- MONTH FORMAT
  34. set theMonth to month of theDate as string
  35. set numMonth to (month of theDate as integer) as string
  36. if the (length of numMonth) < 2 then set numMonth to "0" & numMonth
  37.  
  38. -- DAY FORMAT
  39. set theDay to day of theDate as string
  40. set shortDay to theDay -- shortDay won't have a leading zero
  41. if the (length of theDay) < 2 then set theDay to "0" & theDay
  42. set suffixList to {"st", "nd", "rd"}
  43. set theIndex to last character of theDay as integer
  44. if (theIndex > 0) and (theIndex < 4) and the first character of theDay is not "1" then
  45.     set daySuffix to item theIndex of suffixList
  46. else
  47.     set daySuffix to "th"
  48. end if
  49.  
  50. -- WEEKDAY FORMAT
  51. set longWeekday to weekday of theDate as string
  52. set shortWeekday to characters 1 thru 3 of longWeekday
  53.  
  54. -- YEAR FORMAT
  55. set theYear to year of theDate as string
  56.  
  57. tell application id "DNtp"
  58.     try
  59.         activate
  60.         set theDatabase to open database desiredDatabase
  61.         set myGroup to create location "/Journal/" & theYear & "/" & numMonth in theDatabase
  62.         set recordName to theYear & "-" & numMonth & "-" & theDay & " " & shortWeekday
  63.         if not (exists child recordName of myGroup) then
  64.             set myRecord to create record with {name:recordName, rich text:"", type:rtfd, tags:theYear & "," & theMonth} in myGroup
  65.            
  66.             tell text of myRecord
  67.                 make paragraph at beginning with properties {alignment:center, font:"Zapfino", size:18, color:dateColor} with data (theMonth & space & shortDay & daySuffix & "," & space & longWeekday & return)
  68.                 bold first paragraph
  69.                 unbold last character
  70.                 set properties of last character to {font:"Avenir", size:14}
  71.                
  72.                 --Show the daily quote
  73.                 set myQuote to my getQuote()
  74.                 set the last character to the last character & myQuote & return
  75.                 set alignment of last character to left
  76.                
  77.                 --Show specified number of news headlines
  78.                 set myNews to my getDevonthinkFavorites()
  79.                 set myNewsSize to count of myNews
  80.                 if (myNewsSize = 0) then
  81.                     set myNews to my getNews()
  82.                 end if
  83.                 set the last character to the last character & "HEADLINES:" & return
  84.                 bold last paragraph
  85.                 unbold last character
  86.                 repeat with i from 1 to (count of items of myNews) by 2
  87.                     set the last character to the last character & item i of myNews & return
  88.                     set the URL of the last paragraph to item (i + 1) of myNews
  89.                 end repeat
  90.             end tell
  91.            
  92.         else -- Record already exists, just add new weather/time header
  93.             set myRecord to child recordName in myGroup
  94.         end if
  95.        
  96.         tell text of myRecord
  97.             set the last character to the last character & return & return
  98.             make new paragraph at end with data ((theTime & return) as string)
  99.             set properties of last paragraph to {font:"Avenir", size:16, alignment:left, superscript:4, color:headerColor}
  100.             italicize last paragraph
  101.             set properties of last character to {font:"Avenir", size:16, alignment:left, superscript:0, color:blackColor}
  102.             set last character to last character & "■ "
  103.         end tell
  104.     on error errMsg number errNum
  105.         display alert (localized string "An error occured when adding the note. ") & errMsg
  106.     end try
  107. end tell
  108.  
  109. on getDevonthinkFavorites()
  110.     set myNews to {}
  111.     tell application id "DNtp"
  112.         try
  113.             set getNewsSource to download markup from inoreaderUrl
  114.             set feedItems to get items of feed getNewsSource
  115.             set feedSize to count of feedItems
  116.             if (feedSize < numHeadlines) then
  117.                 set localNumHeadlines to feedSize
  118.             else
  119.                 set localNumHeadlines to numHeadlines
  120.             end if
  121.             if (numHeadlines = 0) then
  122.                 --display alert numHeadlines
  123.                 return myNews
  124.             end if
  125.             set getNewsFeed to items 1 thru localNumHeadlines of feedItems
  126.             repeat with theItems in getNewsFeed
  127.                 set end of myNews to title of theItems
  128.                 set end of myNews to link of theItems
  129.             end repeat
  130.         end try
  131.         return myNews
  132.     end tell
  133. end getDevonthinkFavorites
  134.  
  135. on getQuote()
  136.     tell application id "DNtp"
  137.         try
  138.             set myQuote to ""
  139.             set getSource to download markup from quoteOfDayUrl
  140.             set getFeed to get items of feed getSource
  141.             if items of getFeed is not {} then
  142.                 set randItem to some item of getFeed
  143.                 set myQuote to description of randItem & return & "=    " & title of randItem & "    =" & return
  144.             end if
  145.         end try
  146.         return myQuote
  147.     end tell
  148. end getQuote
  149.  
  150. --Get the news headlines
  151. on getNews()
  152.     set myNews to {}
  153.     tell application id "DNtp"
  154.         try
  155.             set getNewsSource to download markup from genericNewsUrl
  156.             set feedItems to get items of feed getNewsSource
  157.             set feedSize to count of feedItems
  158.             if (feedSize < numHeadlines) then
  159.                 set localNumHeadlines to feedSize
  160.             else
  161.                 set localNumHeadlines to numHeadlines
  162.             end if
  163.             if (numHeadlines = 0) then
  164.                
  165.                 return myNews
  166.             end if
  167.             --display alert numHeadlines
  168.            
  169.             set getNewsFeed to items 1 thru localNumHeadlines of feedItems
  170.             repeat with theItems in getNewsFeed
  171.                 set end of myNews to title of theItems
  172.                 set end of myNews to link of theItems
  173.             end repeat
  174.         end try
  175.         return myNews
  176.     end tell
  177. end getNews
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top