Method: StatsCollect::Locations::MySpace#getBlogs
- Defined in:
- lib/StatsCollect/Locations/MySpace.rb
#getBlogs(oStatsProxy, iMechanizeAgent, iConf) ⇒ Object
Get the blogs statistics
- Parameters
-
oStatsProxy (StatsProxy): The stats proxy to be used to populate stats
-
iMechanizeAgent (Mechanize): The agent reading pages
-
iConf (map<Symbol,Object>): The configuration
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/StatsCollect/Locations/MySpace.rb', line 199 def getBlogs(oStatsProxy, iMechanizeAgent, iConf) # TODO: Be able to get the list of blogs using MySpace only, without config # Parse each blog ID given from the conf. lLstBlogsRead = [] iConf[:BlogsID].each do |iBlogID| # Get the blog page lBlogPage = iMechanizeAgent.get("http://www.myspace.com/#{iConf[:MySpaceName]}/blog/#{iBlogID}") lBlogTitle = lBlogPage.root.css('h2.post-title').first.content lNbrLikes = 0 lStrLikes = lBlogPage.root.css('span.like span.likeLabel').first.content if (!lStrLikes.empty?) lNbrLikes = Integer(lStrLikes.match(/\((\d*)\)/)[1]) end lNbrReads = 0 lStrReads = lBlogPage.root.css('li.blogCommentCnt span').first.content if (!lStrReads.empty?) lNbrReads = Integer(lStrReads.match(/\((\d*)\)/)[1]) end oStatsProxy.add_stat(lBlogTitle, 'Blog likes', lNbrLikes) oStatsProxy.add_stat(lBlogTitle, 'Blog reads', lNbrReads) lLstBlogsRead << lBlogTitle end log_debug "#{lLstBlogsRead.size} blogs read: #{lLstBlogsRead.join(', ')}" end |