# Trying to parse stream.twitter.com, please help

**URL:** <https://www.ruby-forum.com/t/trying-to-parse-stream-twitter-com-please-help/172113>\
**Category:** Ruby\
**Created:** [July 15, 2009, 3:15am UTC](https://www.ruby-forum.com/t/trying-to-parse-stream-twitter-com-please-help/172113 "2009-07-15T03:15:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 15, 2009, 3:15am UTC](https://www.ruby-forum.com/t/trying-to-parse-stream-twitter-com-please-help/172113/1 "2009-07-15T03:15:50Z")

</div>

I’m having no luck working on this, and it’s my first attempt at such a  
process. Here is the code as it is now. When I run the file, I’m  
testing it against my own twitter account, and I see in the ‘% Received’  
it gets about 1100 bytes each time I update, but nothing else works  
beyond that.

This is a job qualifier, any help is appreciated.

```auto
require "rubygems"
require "json"

BASE = "http://stream.twitter.com/"
MODE = "follow.json"
USER = "-u----------:-------"

USERS = [26079932]

IO.popen("curl -d @following #{BASE}#{MODE} #{USER}") do |io|
  begin
    while line = io.gets
      status = line.length > 2 ? JSON.parse(line) : nil
      if status
        if status["user"]["screen_name"] == 'my_screen_name'
          File.new("update_file", 'a').puts "hello"
          #`echo \"#{status[:user][:id]}\" >> update_file`
        end
      end
    end
  rescue
    # connection lost
  end
end
```

---

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 15, 2009, 3:38am UTC](https://www.ruby-forum.com/t/trying-to-parse-stream-twitter-com-please-help/172113/2 "2009-07-15T03:38:21Z")

</div>

My god how low has the world gotten - it’s one thing for a kid to beg  
for  
code to get a high school grade in a class they probably don’t care  
about -  
but when an adult actually sticks up their hand in a room of  
professionals  
and begs for assistance to cheat a company out of money what the hell  
have  
we become. If you cannot perform the job (and can’t even figure out how  
to  
google the answer at least) then please have the decency to not steal  
the  
time and money of the company who you are trying to steal from.

John W Higgins

---

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 15, 2009, 3:51am UTC](https://www.ruby-forum.com/t/trying-to-parse-stream-twitter-com-please-help/172113/3 "2009-07-15T03:51:37Z")

</div>

That’s very assuming. Good job, you’re typical.

---

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 15, 2009, 3:55am UTC](https://www.ruby-forum.com/t/trying-to-parse-stream-twitter-com-please-help/172113/4 "2009-07-15T03:55:57Z")

</div>

A man of such integrity as John W Higgins would surely code in the  
middle of Wichita for $10/hr and have an open case with SRS Vocational  
Rehab. How about it, Higgs?

---

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 15, 2009, 4:05am UTC](https://www.ruby-forum.com/t/trying-to-parse-stream-twitter-com-please-help/172113/5 "2009-07-15T04:05:48Z")

</div>

My sincerest sympathy (I can’t think of a better term here but I mean no  
disrespect), on whatever condition/situation placed you in the situation  
that required any form of rehab.

However, clearly if one looked at your original request it’s a very  
different situation then what you now state. Maybe in the future when  
you  
make a request that clearly could be viewed as a negative request you’ll  
put  
a little more context around it so it doesn’t look like you are doing  
something dishonest.

Best of luck to you and your family!

John W Higgins

---

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 15, 2009, 4:07am UTC](https://www.ruby-forum.com/t/trying-to-parse-stream-twitter-com-please-help/172113/6 "2009-07-15T04:07:18Z")

</div>

I’ve been working on this for five hours and the closest thing this week  
old problem has to a “solution” appears here  
[http://blog.signalnine.net/?p=29](http://blog.signalnine.net/?p=29)

I’ve asked in the #Ruby channel for 2 hours

You can all f\*ck yourselves.

---

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 15, 2009, 2:50pm UTC](https://www.ruby-forum.com/t/trying-to-parse-stream-twitter-com-please-help/172113/7 "2009-07-15T14:50:55Z")

</div>

Finally made some progress, which means one less grudge 🙂 I’m  
guessing this thread will get some traffic in the near future, so I’m  
posting what I believe is a good starting block. While it’s not a  
parsing solution, it should aim in the right direction.

require ‘rubygems’  
require ‘json’

BASE\_URL = “[http://stream.twitter.com/spritzer.json](http://stream.twitter.com/spritzer.json)”  
USER = “-uuser\_name:password”

File.open(“update\_file”, “a”) do |f|  
IO.popen(“curl #{BASE\_URL} #{USER}”) do |p|  
p.each do |status|  
f.puts status  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![caiwangqin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/4bbf92/32.png) [@caiwangqin](https://www.ruby-forum.com/u/caiwangqin)\
**Post date:** [July 15, 2009, 10:13am UTC](https://www.ruby-forum.com/t/trying-to-parse-stream-twitter-com-please-help/172113/8 "2009-07-15T10:13:19Z")

</div>

FWIW, why are you trying to use an external process within the ruby  
script?

A cursory search in twitter’s and in google will tell you that you  
should be able to parse the stream directly. Look up open-uri docs -  
that should get you someplace.
