Created
December 12, 2012 23:48
-
-
Save jordanorelli/4272799 to your computer and use it in GitHub Desktop.
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
package main | |
import ( | |
"bufio" | |
"encoding/json" | |
"log" | |
"net/http" | |
) | |
func main() { | |
username, password, client := "", "", new(http.Client) | |
req, err := http.NewRequest("GET", "https://stream.twitter.com/1/statuses/filter.json?track=tumblr", nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
req.SetBasicAuth(username, password) | |
res, err := client.Do(req) | |
if err != nil { | |
log.Fatal(err) | |
} | |
reader := bufio.NewReader(res.Body) | |
for { | |
line, err := reader.ReadBytes('\r') | |
if err != nil { | |
continue | |
} | |
var item struct { | |
Text string `json:"text"` | |
} | |
json.Unmarshal(line, &item) | |
log.Println(item.Text) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
add you username and password in line 11 to get this to work. Will display the time received and the text of every tweet that mentions the word "tumblr". The volume is quite amazing.
uses only the Go standard library, so the only requirement is that you have the language. After adding your username and password, you can run it with
go run tumblr.go
. Change the search term in line 13 if you'd like to search for something else.(I don't know why the indentation is getting screwed up in line 4, even after I ran this through Go fmt; it seems like github is changing the whitespace)