Skip to content

Commit

Permalink
user tweets are working again, minus location
Browse files Browse the repository at this point in the history
  • Loading branch information
brentsowers1 committed Dec 17, 2011
1 parent 85f5bb9 commit 6f30afa
Showing 1 changed file with 35 additions and 38 deletions.
73 changes: 35 additions & 38 deletions lib/twitterscour.rb
Expand Up @@ -33,49 +33,46 @@ def self.from_user(username, number_of_pages=1, fetch_location_info=false)
pagination_html = rsp.body

main_page = Nokogiri::HTML(rsp.body)
authenticity_token = main_page.css("input#authenticity_token").first[:value]


while rsp.code == 200
page_body = Nokogiri::HTML(tweets_html)

new_tweets = page_body.css('li.status').collect do |tw|
new_tweets = page_body.css('div.tweet').collect do |tw|
t = Tweet.new
if tw[:class] =~ /.* u\-(.*?) .*/
t.author_name = $1
end
t.text = tw.css("span.entry-content").text
t.author_name = tw[:"data-screen-name"]
t.text = tw.css("div.tweet-text").text
# For some reason, time isn't in quotes in the JSON string which causes problems
t.time = Time.parse(tw.css("span.timestamp").first[:data].match(/\{time:'(.*)'\}/)[1])
meta_data_str = tw.css("span.entry-meta").first[:data]
if meta_data_str.length > 2
meta_data = JSON.parse(meta_data_str)
t.author_pic = meta_data["avatar_url"]
place_id = meta_data["place_id"]
if place_id && fetch_location_info
if locations[place_id]
t.location = locations[place_id]
else
geo_result = HTTParty.get("http://twitter.com/1/geo/id/#{place_id}.json?authenticity_token=#{authenticity_token}&twttr=true")
if geo_result && geo_result.code == 200 && geo_result.body &&
geo_result.body =~ /^\{.*/
geo_data = JSON.parse(geo_result.body)
if geo_data["geometry"] && geo_data["geometry"]["coordinates"]
loc = TweetLocation.new
loc.place_name = geo_data["name"]
if geo_data["geometry"]["type"] == "Point"
loc.center = geo_data["geometry"]["coordinates"]
elsif geo_data["geometry"]["type"] == "Polygon"
loc.bounding_box = geo_data["geometry"]["coordinates"].first
ll_sums = loc.bounding_box.inject([0,0]) {|sum, p| [sum[0] + p[0], sum[1] + p[1]]}
loc.center = [ll_sums[0] / loc.bounding_box.length, ll_sums[1] / loc.bounding_box.length]
end
t.location = loc
locations[place_id] = loc
end
end
end
end
end
t.time = Time.parse(tw.css("span.js-tweet-timestamp")[0][:"data-time"])
#meta_data_str = tw.css("span.entry-meta").first[:data]
#if meta_data_str.length > 2
# meta_data = JSON.parse(meta_data_str)
# t.author_pic = meta_data["avatar_url"]
# place_id = meta_data["place_id"]
# if place_id && fetch_location_info
# if locations[place_id]
# t.location = locations[place_id]
# else
# geo_result = HTTParty.get("http://twitter.com/1/geo/id/#{place_id}.json?authenticity_token=#{authenticity_token}&twttr=true")
# if geo_result && geo_result.code == 200 && geo_result.body &&
# geo_result.body =~ /^\{.*/
# geo_data = JSON.parse(geo_result.body)
# if geo_data["geometry"] && geo_data["geometry"]["coordinates"]
# loc = TweetLocation.new
# loc.place_name = geo_data["name"]
# if geo_data["geometry"]["type"] == "Point"
# loc.center = geo_data["geometry"]["coordinates"]
# elsif geo_data["geometry"]["type"] == "Polygon"
# loc.bounding_box = geo_data["geometry"]["coordinates"].first
# ll_sums = loc.bounding_box.inject([0,0]) {|sum, p| [sum[0] + p[0], sum[1] + p[1]]}
# loc.center = [ll_sums[0] / loc.bounding_box.length, ll_sums[1] / loc.bounding_box.length]
# end
# t.location = loc
# locations[place_id] = loc
# end
# end
# end
# end
#end
t
end
tweets = tweets.concat(new_tweets)
Expand Down

0 comments on commit 6f30afa

Please sign in to comment.