Method: StatsCollect::Locations::MySpace#getFriendsList
- Defined in:
- lib/StatsCollect/Locations/MySpace.rb
#getFriendsList(oStatsProxy, iMechanizeAgent) ⇒ Object
Get the friends list
- Parameters
-
oStatsProxy (StatsProxy): The stats proxy to be used to populate stats
-
iMechanizeAgent (Mechanize): The agent reading pages
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/StatsCollect/Locations/MySpace.rb', line 229 def getFriendsList(oStatsProxy, iMechanizeAgent) lFriendsPage = iMechanizeAgent.get('http://www.myspace.com/my/friends/grid/page/1') # Keep track of the last first friend of the page, as we will detect ending page thanks to it. lLastFirstFriend = nil lFriendsMap = {} lIdxPage = 2 while (lFriendsPage != nil) lFirstFriend = nil lFriendsPage.root.css('ul.myDataList li').each do |iFriendNode| if (iFriendNode['data-id'] != nil) # We have a friend node lFriendID = iFriendNode['data-id'] lFriendName = nil iFriendNode.css('div div.vcard span.hcard a.nickname').each do |iFriendLinkNode| lFriendName = iFriendLinkNode['href'][1..-1] if (lFriendName == nil) log_err "Could not get friend's name for ID #{lFriendID}: #{iFriendLinkNode}" end lFriendsMap[lFriendID] = lFriendName end if (lFirstFriend == nil) # Check if the page has not changed if (lLastFirstFriend == lFriendID) # Finished break end lFirstFriend = lFriendID end end end lLastFirstFriend = lFirstFriend # Get next page if we did not reach the end if (lLastFirstFriend == nil) lFriendsPage = nil else lFriendsPage = iMechanizeAgent.get("http://www.myspace.com/my/friends/grid/page/#{lIdxPage}") lIdxPage += 1 end end oStatsProxy.add_stat('Global', 'Friends list', lFriendsMap) end |