-
-
Save Watson1978/3029741 to your computer and use it in GitHub Desktop.
macruby reject bugs tweets
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
#!/usr/bin/env macruby -wKU | |
framework 'Foundation' | |
## first example reject works great | |
new_array = ["test", "test 1", "Test 2", "Test 3", 10].reject {|test| test.is_a?(Fixnum) } | |
p new_array | |
## second example it still showing tweets with iso_language_code == en | |
twitter_search = NSURL.URLWithString("http://search.twitter.com/search.json?q=@rubymotion&rpp=100") | |
data = NSData.dataWithContentsOfURL(twitter_search) | |
opts = NSJSONReadingMutableContainers | NSJSONWritingPrettyPrinted | |
json = NSJSONSerialization.JSONObjectWithData(data, options:opts, error:nil) | |
tweets = json[:results] | |
tweets = Array.new(tweets) | |
results = tweets.select { |tweet| tweet.is_a?(Hash) } | |
.reject { |tweet| tweet[:iso_language_code] == "en" } | |
.map { |tweet| "%<iso_language_code>s - %<from_user_name>s : %<text>s" % tweet } | |
puts results |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment