Skip to content

Instantly share code, notes, and snippets.

@troutcolor
Last active February 10, 2019 13:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troutcolor/820f6c42919512275efac42a45432298 to your computer and use it in GitHub Desktop.
Save troutcolor/820f6c42919512275efac42a45432298 to your computer and use it in GitHub Desktop.
AppleScript Get your favourites from micro.blog find photos and make thumbnail grid needs JSON Helper and an app token from your micro.blog account
(*
* Inspired by smokey
* https://gist.github.com/sardisson/e50286e17c8f2f39bfec9429ed5f46cd
* url for thubnail from @smokey too
* html Thumbnail image griid from Micro.blog favs
* NEEDS JSON Helper free from
*https://itunes.apple.com/gb/app/json-helper-for-applescript/id453114608?mt=12
* Needs a App token from micro.blog/account
* NO ERROR CHECKING
* updated to use cloudimage you need a token from cloudimage.io iin CLOUDIMAGETOKEN below.
*)
set apptoken to "GET_AN_APP_TOKEN"
set myDate to current date
set myNewDate to myDate - (7 * days)
set scrpt to "curl -X GET -H \"Authorization: Bearer " & apptoken & "\" \"http://micro.blog/posts/favorites\""
set thejson to do shell script scrpt
tell application "JSON Helper"
set links to read JSON from thejson
set linkstopost to ""
repeat with n from 1 to count of item 4 of items of links
set link to item n of item 4 of items of links
set tusername to username of _microblog of author of link
set tdate_published to date_published of link
set tid to |id| of link
set tcontent_html to content_html of link
set turl to |url| of link
set aslinkdate to my convertDate(tdate_published)
if aslinkdate < myNewDate then exit repeat
if ((offset of "<img" in tcontent_html) > 0) then
set imgsrc to my getFirstImageSrc(tcontent_html)
set linkstopost to linkstopost & "<a href='" & turl & "'><img src='https://CLOUDIMAGETOKEN.cloudimg.io/cover/120x120/n/" & imgsrc & "'></a>"
end if
end repeat
tell application "BBEdit"
make new text window ¬
with properties {contents:linkstopost}
activate
end tell -- application "BBEdit"
end tell
to getFirstImageSrc(html)
set AppleScript's text item delimiters to "<img"
set html to text item 2 of html
set AppleScript's text item delimiters to ">"
set html to text item 1 of html
try
set AppleScript's text item delimiters to "src=\""
set html to text item 2 of html
set AppleScript's text item delimiters to "\""
return text item 1 of html
on error
set AppleScript's text item delimiters to "src='"
set html to text item 2 of html
set AppleScript's text item delimiters to "'"
return text item 1 of html
end try
end getFirstImageSrc
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