Created
October 2, 2012 03:48
-
-
Save kristianfreeman/3816058 to your computer and use it in GitHub Desktop.
Tent.is posts to Day One
This file contains hidden or 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
## Tent.io work | |
require 'json' | |
require 'time' | |
# Change these to suit your needs | |
# You probably don't want my posts. | |
username = "kmf" | |
post_location = "/Users/kristian/Dropbox/ifttt/tent" | |
Dir.chdir post_location | |
puts "Waiting for download..." | |
`curl -s -o #{post_location} https://#{username}.tent.is/tent/posts` | |
json = File.read('posts') | |
posts = JSON.parse(json) | |
skip = Array.new | |
# Uncomment the following lines after running for the first time | |
# skiplist = File.open('lastid') | |
# list = skiplist.readline.to_s.split(',') | |
posts.reverse_each do |post| | |
next if post["content"]["text"].nil? | |
# Uncomment the following line after running for the first time | |
# next if list.include?(post["id"]) | |
text = post["content"]["text"] | |
id = post["id"] | |
skip.push(id) | |
unDate = post["published_at"] | |
time = Time.at(unDate).to_time.strftime("%I:%M %p") | |
date = Time.at(unDate).to_time.strftime("%m/%d/%Y %I:%M%p") | |
post = "[[#{time}](http://#{username}.tent.is/posts/#{id})]: #{text} | |
Posted on Tent.is" | |
`echo "#{post}" | dayone -d="#{date}" new` | |
end | |
if !skip.empty? | |
File.open('lastid', 'a') {|f| f.write(skip.join(","))} | |
else | |
puts "No new posts found." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Things to know about this gist
19
,20
, and26
) to stop the script from adding posts it has already seen.This is really rough, but I wanted a way to import these into Day One so I don't lose track of them. There might be (hint, probably are) bugs, so fork away!
PS — if you want to use this all power-user-y, you should use a cron job or maybe Lingon with this.