Tag: client


Google Reader and Zend_Http_Client Saves Time

November 16th, 2008 — 6:24pm

I’ve been working a lot on Florida Death Metal lately. Part of that means that I need to know news, as it happens, from a lot of different sources. That can be difficult (and a pain in the ass) to keep track of. The last thing I want to do, is visit 50 different sites every 15 minutes to see if there’s any news I should know about.

The first thing I did, to filter input, was to setup a Google Reader account for Florida Death Metal. At least this allowed me to see updates from a variety of other sites in a single place. This also allows me to search through those new listings for keywords to bands and events I think are important to know about.

This still requires me to visit Google Reader, and parse through a lot of stuff (routinely over 1000 new items) to find out what’s going on in the world. The real dilemma I was having, was trying to implement an active alert system to news going on around me. The active part, was me actively searching through Google Reader for information relevant to Florida Death Metal. 

Needless to say, this started to suck. I have a great full time job, a wonderful wife, and a million other things I like to do with my spare time. Spending my days and nights on Google Reader, struggling to keep up with news for a project blew.

I love Florida Death Metal. I’ve never been involved in something that means so much to me. However, there are only so many days in the week, and so much time in each of those days. I need a way to passively keep up with relevant news and events. I needed some automation, so I could spend time hanging drapes for Melissa, or having a beer with Rob.

Enter Zend_Http_Client ….

One of my favorite programming tricks is breaking down requests to servers, and finding a way to do them programatically. So, I got to thinking about how I could parse through all of my stuff in Google Reader. For each of the views in Google Reader, there is an associated RSS feed. Well, that makes things simple enough. I could just grab the RSS feed and parse it. 

One minor detail, the RSS feeds aren’t publicly available. You have to be logged in to use them. This makes sense. I imagine Google doesn’t want to be used as an aggregator of RSS feeds to be used as a proxy to other sites. Sorry :/

So, here’s a breakdown of what I needed to write a script to do:

  1. Login to Google
  2. Grab the RSS Feed for ‘All Items’
  3. Parse the RSS Feed for keywords relevant to Florida Death Metal
  4. Email me alerts (if there are matches)

Not too bad. So, Here’s the script I came up with. I hope you like it :

 
<?php
/*
Description: Script to parse through a google reader aggregation of content for keywords
Version: 1.0
Author: Cory Collier
Author URI: http://corycollier.com/
*/
 
//Define the constants required for the script
define('GOOGLE_PASSWORD', 	'<your password here>');
define('GOOGLE_RSS_URI', 		'<the url for your google reader rss feed>');
define('GOOGLE_LOGIN_URI',		'https://www.google.com/accounts/ServiceLoginAuth?service=reader');
define('GOOGLE_LOGIN_EMAIL', 	'<your gmail account username / email>');
define('MAILER_FROM_ADDR',		'<where the email should come from>');
define('MAILER_TO_ADDR',		'<where the email should go to>');
define('MAILER_SUBJECT',		'Google Reader Parsing');
 
/*
* a Zend Framework Installation _MUST_ be located on the include path for PHP
*/
require 'Zend/Loader.php';
Zend_Loader::registerAutoload();
 
//Instantiate a new Zend_Http_Client, with the google login url
$client = new Zend_Http_Client(GOOGLE_LOGIN_URI);
 
/*
 * Set the client cookie jar ...
 * Set the method to POST ..
 * Set the parameters to post with
 */
$client->setCookieJar()
	->setMethod(Zend_Http_Client::POST)
	->setParameterPost(array(
		'continue'		=> GOOGLE_RSS_URI,
		'service'		=> 'reader',
		'niu'			=> 1,
		'hl'			=> 'en', 
		'Email'		=> GOOGLE_LOGIN_EMAIL,
		'Passwd'		=> GOOGLE_PASSWORD,
		'PersistentCookie'	=> 'yes',
		'asts'			=> ''
));
 
//make the login request, and store the response in the $response variable ...
$response = $client->request('POST');
 
//If the response was successful, change the uri value for the client object
// to the appropriate rss file for parsing
$client->setUri(GOOGLE_RSS_URI)
 
		//Change the request method to GET
		->setMethod(Zend_Http_Client::GET); 
 
//send the request, and store the results of it
$response = $client->request();
 
//Initialize an array of keywords to look for
$keywords = array (
	//Whatever your keywords are you're looking for
);
 
//SimpleXML is great!
$sx = simplexml_load_string ($response->getBody());
 
//Iterate through each of the retrieved entries
foreach ($sx->entry as $entry ) 
{	//Now, iterate through each of the defined keywords / keyphrases
    foreach ( $keywords as $keyword ) 
    {	//First, check to see if the title contains a keyword / keyphrase
        if ( stristr((string)$entry->title, $keyword) ) 
        {	//Append any matches to the matches arrays
            $matches[] = (string)$entry->link['href'];
        }
    	//Next, check to see if there are any matches in the summary
        if ( stristr((string)$entry->summary, $keyword) ) 
        {	//same deal: If there are matches, add them to the stack
            $matches[] = (string)$entry->link['href'];
        }
    } //END keyword iteration
 
} // END posting iteration
 
//IF matches were found, send an email
if(count($matches)) 
{	//Initialize a variable to store a mesage in
    $message = '';
 
    //Iterate through each of the matches
    foreach($matches as $match)
    {	//For each of the matches, append them to the message string, separated 
    	// by newlines
        $message .= "\n" .  $match;  
    }
    //Initialize a new Zend_Mail object 
    $mail = new Zend_Mail;
 
    //Set the parameters necessary to send a message 
    $mail->addTo(MAILER_TO_ADDR)
        ->setFrom(MAILER_FROM_ADDR)
        ->setSubject(MAILER_SUBJECT)
        ->setBodyText($message);
 
    //I never trust email, so wrap the email execution in a try/catch statement
    try  
    {	//Send the mail
        $mail->send();   
    } catch (Exception $e ){
        //Do something here
    }
}

Wrapping all of this up, I stuck this script on a spare debian box at my house, and setup a cronjob to run the script every 15 minutes. It saves me a lot of time. I’d love to hear some feedback from y’all about how I got this done. I’m a script guy at heart. So, this stuff is super fun for me.

Wrapping all of this up, I stuck this script on a spare debian box at my house, and setup a cronjob to run the script every 15 minutes. It saves me a lot of time. I'd love to hear some feedback from y'all about how I got this done. I'm a script guy at heart. So, this stuff is super fun for me.

I know I should have checked the success of the initial login attempt before assuming the second request would get anything at all. Keep in mind though, this is a script I use to make my own life easier. Exceptions being thrown here cause me no harm. If I don't get anything, I can check my error logs for issues. Not a perfect solution, but it's working pretty well for me now. :D

1 comment » | tech

Holy Crap! Updates!!!

May 20th, 2008 — 6:00pm

I don’t even know how to begin to talk about everything that’s been going on since the last time I’ve written here. My buddy got married. I’ve dealt with server issues (again). I’ve been promoted. Some stuff I can’t even talk about!

I’ve written since Matt and Suzanne were married, but I’ve yet to write about it. I was the best man, so I guess I’d be as good as anyone to say something about their wedding. It was a beautiful wedding. Matt and Suzanne are a great couple, and it’s been awesome to watch their relationship grow to what it is today. I’d do just about anything for those two, and I couldn’t be happier for them now.

I was promoted to Product Manager of MemberFuse lately too. If that sounds serious, it’s because it is. I’m the one in charge of the direction that product will take. I’ve recently gotten pretty hooked on what ning is doing, and I’m considering using them as a platform for MemberFuse. We’ll see if Sterling and Derek will buy into the concept, but I’d rather not re-invent the wheel.

Server problems…. Grrrrrrr……

Last Thursday, I noticed all of the sites on one of my servers were down. I tried to remote into the server, but I couldn’t. So I RDP’d to another server on that network and performed a remote restart. The only problem was, the server wouldn’t restart. I had the client ship me the server, and after a couple hours of tinkering it was apparent that someone had sabotaged the server.

That’s a long story, that I’ll probably write about later. The short version is: it’s fixed, and I’m using Wordpress now. For those of you who had left comments before, they’re gone now. I’m really sorry about that :/ The client’s sites are going to take some time to get back to full capacity, but I should have the base of it done tonight.

Comment » | personal

It’s Tough Being Geeky

July 9th, 2007 — 9:44pm

Being a geek is a tough job. Just keeping up with the constant changes means you have to really want to spend the time doing it. It also helps that your significant other is fairly independent, since being a geek isn’t something you can share (unless your wife / husband is a geek too).

Clients don’t make your job any easier. Any profession where the client can’t comprehend what it takes to accomplish the job, is a career frought with distrust. How many clients always say things to geeks like:

“It always worked before”

“You want how much money?”

“I don’t know, the whole thing is broken”

The last statement is probably one of the more common things I hear, when I help people with their computer issues. It’s also one of the things that makes being a network adminstrator / computer consultant the hardest. Imagine how difficult it is to fix a problem when the information you have to work with is “the computer keeps crashing”. If the only thing you told your doctor was, “I don’t feel good”, do you think he could help you?

What’s especially difficult is having proof of a client’s own fault, but needing the cash they’re going to pay to fix an issue. I’ve worked on networks where the boss was responsible for bringing the whole thing down, due to inappropriate internet viewing. The boss want’s to know who is costing them all of this money, and it’s actually their own fault. Try to explain that one, and still expect to get paid what you deserve.

Hackers (read: black hat) don’t make life any easier. Life is already filled with enough work, then a kid using someone elses program finds a way to attack your site / network. That vacation you had planned with the family? Forget it. Now, try to explain that to your wife / husband. Much like a doctor, work is not 9 – 5, and when an issue arises, you’d better be ready to deal with it, immediately.

I’ve performed network upgrades that took 200 hours of work in 2 weeks to accomplish. The client pays for a network upgrade, and doesn’t like to hear about “change orders” to the agreement. If you missed an “obvious” detail of their network, then that’s your fault.

Another amazingly irritating thing clients do: think you can run their software for them. I have an engineering degree. I write software. I fix networks. I have no idea how to do your business. So when you want the computer guy to tell you how to use your accounting / billing / CRM software, don’t expect much. Most geeks know how to use the software, but it’s up to you to learn it and use it for yourself.

Finally, and perhaps the most frustrating thing about being a geek, is the lack of respect we get for the job we do. It’s irritating to see people with no skillset in life but the ability to talk, treat you as fodder for their enterprise. The jobs we geeks do are not expendable. The next time you dismiss the guy who writes your website, or fixes your e-mail problem, think about what you’d do without him / her.

Comment » | personal, work

Windows Server SBS 2003 and RRAS Headaches

June 30th, 2007 — 1:04pm

Not long ago I got the task of setting up a small server for an engineer in our building. He has a small office with one other person working for him. The idea was for him to have a central repository for files, a system backing up those files, and the ability to remotely access all of those files.

I recommended a Windows SBS 2003 box. The client obliged.

All was fine until the issue of VPN came up. I’ve done VPN’s before, but usually it’s through hardware, not through the OS. The client eventually was paid in full, and the issue still wasn’t completely resolved. I felt terrible about it, so I made it my priority to fix. The client was really cool, and I didn’t want them to feel cheated or upset in any way.

I won’t go through the whole tutorial on how to setup an SBS box, but I will say that usually, it’s very intuitive. Well, when I set up the box, I configured it to work on one subnet. However, the modem supplied to the client wouldn’t allow GRE packets through, so they needed to get a new modem.

When that modem arrived, it didn’t work with their existing Linksys wireless router. So I used the modem as the router, and plugged the wireless box into it, and ran it as a separate subnet. Keep in mind, this was after I had already configured the SBS box for the previous subnet.

I thought I had configured the server to work with the new network settings, but I missed a couple of items.

Clear ARP cache.

Since RRAS was started, you couldn’t clear the ARP cache (the table with the addresses of machines according to the old subnet). I had to stop the RRAS service to clear the ARP cache. Keep that in mind if you have to move an SBS box from one network to another.

Change ALL network settings. When I changed the TCP/IP information for the network adapter (only one), I only changed the information on the front dialog box. Which means I forgot to change the WINS information! Since the client was using VPN so he could navigate to files on the network, that was pretty important.

Also, I needed to add the dns suffix to the DNS settings area as well.

The moral of the story, take the time to get it done right the first time.

Comment » | Uncategorized

Back to top