Created
October 20, 2017 14:17
-
-
Save troutcolor/833045266f1b6c35c8ec7cc7667be415 to your computer and use it in GitHub Desktop.
An appleScript that pulls recent links from pinboard, make a html list from the and opens in BBEdit ready to edit and post to blog. lins in the description beginning with > are made into blockquotes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set myDate to current date | |
set myNewDate to myDate - (8 * days) | |
tell application "JSON Helper" | |
set links to fetch JSON from "https://feeds.pinboard.in/json/u:johnjohnston/" | |
--set links to fetch JSON from "https://feeds.pinboard.in/json/u:johnjohnston/t:classroom" | |
set y to count of links | |
set linkstopost to "" | |
repeat with thislink from 1 to count of links | |
set link to item thislink of links | |
set tURL to u of link | |
set title to d of link | |
set description to n of link | |
set htmldexcription to "" | |
set theParagraphs to every paragraph of description | |
repeat with theParagraph in theParagraphs | |
try | |
--I put > before quotes in the description when I remember | |
--the try means empty lines don't get included and don't blowup when we get character 1 | |
if character 1 of theParagraph = ">" then | |
set theParagraph to text 2 thru -1 of theParagraph | |
set htmldexcription to htmldexcription & "<blockquote>" & theParagraph & "</blockquote>" & return | |
else | |
set htmldexcription to htmldexcription & theParagraph | |
end if | |
end try | |
end repeat | |
set linkdate to dt of link | |
set aslinkdate to my convertDate(linkdate) | |
if aslinkdate < myNewDate then exit repeat | |
set newlink to "<li><a href='" & tURL & "'>" & title & "</a> " & htmldexcription & "</li>" | |
set linkstopost to linkstopost & return & newlink | |
end repeat | |
set linkstopost to "<ul class='linklist'>" & linkstopost & "<ul>" | |
tell application "BBEdit" | |
make new text window ¬ | |
with properties {contents:linkstopost} | |
activate | |
end tell -- application "BBEdit" | |
end tell | |
to convertDate(textdate) | |
--https://gist.github.com/RichardHyde/3386ac57b55455b71140 | |
set resultDate to the current date | |
set the year of resultDate to (text 1 thru 4 of textdate) | |
set the month of resultDate to (text 6 thru 7 of textdate) | |
set the day of resultDate to (text 9 thru 10 of textdate) | |
set the time of resultDate to 0 | |
if (length of textdate) > 10 then | |
set the hours of resultDate to (text 12 thru 13 of textdate) | |
set the minutes of resultDate to (text 15 thru 16 of textdate) | |
if (length of textdate) > 16 then | |
set the seconds of resultDate to (text 18 thru 19 of textdate) | |
end if | |
end if | |
return resultDate | |
end convertDate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment