Last active
December 14, 2015 10:29
-
-
Save jhawthorn/5072567 to your computer and use it in GitHub Desktop.
Set the latest tweet from @Cmdr_Hadfield as desktop background
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
require 'json' | |
require 'open-uri' | |
TIMELINE_URL = 'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=Cmdr_Hadfield&include_entities=true&trim_user=true&exclude_replies=true' | |
class Tweet < Struct.new(:tweet) | |
def media | |
tweet['entities']['media'][0] | |
end | |
def image_url | |
media["media_url"] + ':orig' | |
end | |
def text | |
tweet['text'].gsub(media['url'], '').strip | |
end | |
def write_image filename | |
system %(convert '#{esc image_url}' -fill white -undercolor '#00000080' -gravity South -annotate +0+5 '#{esc text}' '#{esc filename}') | |
end | |
private | |
def esc text | |
text.gsub("'", "''") | |
end | |
end | |
json = open(TIMELINE_URL).read | |
data = JSON.parse(json) | |
tweet = data.detect{|x| x['entities'] && x['entities']['media'] } | |
tweet = Tweet.new(tweet) | |
tweet.write_image '/tmp/bg.jpg' | |
system 'feh --bg-scale /tmp/bg.jpg' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment