parsing the google trends atom feed

Short and sweet : how to grab the google trends atom feed and parse out the links,
in 15 lines.

  1. $feed = simplexml_load_file('http://www.google.com/trends/hottrends/atom/hourly');
  2. $children =  $feed->children('http://www.w3.org/2005/Atom');
  3. $parts = $children->entry;
  4. foreach ($parts as $entry) {
  5.    $details = $entry->children('http://www.w3.org/2005/Atom');
  6.    $dom = new domDocument();
  7.    @$dom->loadHTML($details->content);
  8.    $anchors = $dom->getElementsByTagName('a');
  9.   foreach ($anchors as $anchor) {
  10.     $url = $anchor->getAttribute('href');
  11.     $urltext = $anchor->nodeValue;
  12.     echo 'Link: <a href="' . $url . '" title="' . $urltext . '">' . $urltext . '</a> ';
  13.   }
  14. }

Requires php with simplexml and dom xml. You could use it for a blogfarm script but that’s about all I can think of.

edited 18-12-08 :
$dom->loadHTML((string) $details->content);
to
@$dom->loadHTML($details->content);

Posted in google, php | Tagged , , | 10 Comments

serp tool

I was putting together a serp tool with a database and an emailer on a cronjob, mainly because I am lazy, I always get cranky when I have to type in these keywords again, I ain’t a teletubby.

I wanted an automated one with a history that sends me an email every day, so I started putting on together but I got distracted because the gethost server was shut down and my moms Mary Chapel event blog was on it. My old site was also on it, with my crappy blog, but losing that ain’t half as bad as losing yer moms Mary Chapel blog, that is bad karma.

So I got her a domain and put it on one of my accounts, installed a new blog and made sure it ranks number one in google again. Apart from that I was putting together a scraper and still needed some cron jobs for the scraper scripts.

I found a nice free cron job site, standard 5 jobs a day. It’s free and it works flawless, no hassles. Very nice.

Once I had that I remembered I still had to finish that serp thing as well, so I finished the basic routines today. Still needs some testing, and it could use the yahoo and msn serps. I’ll grab them from a wordpress widget and add some language options, after that it should be a fine tool.

I’ll put the scripts up for download in two or three weeks or something.

Posted in serp, tool | Tagged , | 2 Comments

xml rpc – remote posting with incutio wordpress ixr class

In order to build a successful blog network I need xml-rpc. I read up on xml-rpc, incutio ixr and tried some basic flat file xml rpc. It’s either that or a custom php url to post data to and then use the wordpress functions to process it.

Xml-rpc is a lot easier especially with the WordPress Incutio-IXR class:

  1. include_once('wp-includes/class-IXR.php');
  2.  
  3. //just give us your endpoint and we'll take it from there Sparky…
  4. $client = new IXR_Client('http://tryout.blacknorati.com/xmlrpc.php');
  5.  
  6. // xml rpc post function form :
  7. // metaWeblog.newPost( blog_id, username, password, struct, publish )
  8.  
  9. //struct = structure for post data
  10.  $post['title'] = 'test titel';
  11.  $post['description'] = 'test';
  12.  $post['categories'] = array("frontpage");
  13.  
  14. //use 'query' to interact with the server, set publish to 0 (draft) for now
  15.  if (!$client->query('metaWeblog.newPost', 6, 'user', 'password', $post, 0)) {
  16.  die('Something went wrong – '.$client->getErrorCode().' : '.$client->getErrorMessage());
  17.  }
  18.         echo $client->getResponse();

Normally getResponse will return a PostID for this function.

Is it really that simple ? Yes. I skipped to the IXR_Client because my host does not have xmlrpc running and the IXR_class doesn’t use it, and solutions with email don’t easily allow access to tags and categories.

  1. $post['categories'] = array("frontpage");
  2. $post['mt_keywords']='key1, key2';
  3. $post["mt_allow_comments"] ='closed';
  4. $post['mt_allow_pings']='open';
  5. //$post['mt_tb_ping_urls'] ='url url url';
  6. //$post['enclosure']=array('url', 'length', 'type')';

mt_keywords holds my tags, that’s a bit more flexible than categories. For my blogs the comments are closed (mt_allow_comments), mt_allow_pings is open, and the real tasty bit is the trackbacks (mt_tb_ping_urls : simply urls separated with a blank space, just like in the wordpress form). I played with the Arrousi trackback class, that one has an autodiscover routine, so I can try and fetch a trackback url from the content page I am ‘using’.

I don’t work with enclosures, but to be complete I added it here.

That covers most data I want to send around a blog network. Very nice class, Incutio IXR.

Next week : more nonsense.

Posted in wordpress, xml-rpc | Tagged , | 2 Comments