Skip to content

Instantly share code, notes, and snippets.

@quephird
Created August 2, 2012 20:44
Show Gist options
  • Save quephird/3240475 to your computer and use it in GitHub Desktop.
Save quephird/3240475 to your computer and use it in GitHub Desktop.
Get a hold of the content of a tweet in binary format and convert it to text
; Inspired by a tweet from the self-aware Roomba to Carin Maier
(ns binary-tweet
(:require [clojure.xml :as xml]
[clojure.string :as string]))
(defn binary-to-text [s]
(apply str
(->> s
(partition-all 8)
(map #(apply str %))
(map #(Character/toString (char (Integer/parseInt % 2))))))
)
(defn get-tweet-content [url]
(first
(for [x (xml-seq (xml/parse url)) :when (= :text (:tag x))]
(first (:content x))))
)
(let [tweet-url "https://api.twitter.com/1/statuses/show.xml?id=231100732177252352"]
(-> tweet-url
get-tweet-content
(string/split #"\s+")
second
binary-to-text
println))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment