The site uses cookies that you may not want. Continued use means acceptance. For more information see our privacy policy.

With PHP XScreensaver displays news

A cobbled together script for displaying google news in XScreensaver.

One of my favorite packages that spans the linux distro universe is XScreensaver. Indeed, any OS that uses X can make use of this screensaver package. In setting it up, I found myself drawn to a few specific screensavers that do more than eyecandy. They display text from 1) Host name and time, 2) Static text, 3) Text file, 4) program text output, or 5) URL. So I threw the google news RSS feed URL in and enjoyed seeing the latest news when my screensaver came on.

This provided a problem. Most RSS (and Google’s feed was no exception) provide only brief summaries of their items. I wanted full-text. So, to accomplish this I found the easiest (though not the best) way was to create a PHP script with the help of some prefab scripts (namely Magpie for the RSS and a script [link] to grab the html from each item).

While an imperfect solution, it gives the full stories; the combination of html stripping in PHP and XScreensaver’s HTML parser make it a pretty solid combination.

Screenshot

Please, if you have any suggestions/changes/other similar implementations to shout out about, drop a comment or an e-mail. I’d really like to see what else is out there.

And now the (shoddy) code (Formatted for publication using code2html):

 1 //Needed for magpie:
 2 define('MAGPIE_DIR', './magpierss/');
 3 require_once(MAGPIE_DIR.'rss_fetch.inc');
 4 //From the grabber script:
 5 	$config['start_tag'] = "<p>"; // where you want to start grabbing
 6 	$config['end_tag']   = "</p>"; // where you want to stop grabbing
 7 	$config['show_tags'] = 0; // do you want the tags to be shown when you show the html? 1 = yes, 0 = no
 8 //from the magpie examples:
 9 
10 	//Modified to use a single rss URL
11 	$rss = fetch_rss('http://news.google.com/nwshp?hl=en&ned=us&output=rss');
12 	//Modified to create an explicit array and shuffle it to get a random item.
13 	$rss_array = $rss->items;
14 	shuffle( $rss_array );
15 	foreach ( $rss_array as $key => $item )
16 	{
17 		if ($key > 1) {
18 			break;
19 		}
20 		$config['url'] = $rss_array[1]['link'];
21 		//From grabber script:
22 		$grab = new grabber;
23 		$grab->grabhtml( $config['url'], $config['start_tag'], $config['end_tag'] );
24 		if (!$grab->error) {
25 			foreach( $grab->html[0] as $html )
26 			{
27 				echo htmlspecialchars( $grab->strip( $html, $config['show_tags'], $config['start_tag'], $config['end_tag'] ) ) . "<br />";
28 			}
29 		}
30 	}
31 
32 	//From grabber script:
33 	class grabber
34 	{
35 		var $error = '';
36 		var $html  = '';
37 	
38 		function grabhtml( $url, $start, $end )
39 		{
40 			$file = file_get_contents( $url );
41 		
42 			if( $file )
43 			{
44 				if( preg_match_all( "#$start(.*?)$end#s", $file, $match ) )
45 				{				
46 					$this->html = $match;
47 				}
48 				else
49 				{
50 					$this->error = "Tags cannot be found.";
51 				}
52 			}
53 			else
54 			{
55 				$this->error = "Site cannot be found!";
56 			}
57 		}
58 	
59 		function strip( $html, $show, $start, $end )
60 		{
61 			if( !$show )
62 			{
63 				$html = str_replace( $start, "", $html );
64 				$html = str_replace( $end, "", $html );
65 				
66 				//Added the PHP function strip_tags and strip any numeric html character references:
67 				$pattern = '/^\&\#(\d+);$/u';
68 				return preg_replace( $pattern, '', strip_tags( $html ) );
69 			}
70 			else
71 			{
72 				return $html;
73 			}
74 		}
75 	}

dpkg-buildpackage subversion tutorial

Grabbing source from subversion and making a package out of it (Debian).

This is a brief writeup of how to take a package or version of package that’s not yet in incoming debian but is on the subversion. Please note it pertains to sid/unstable, though may be applicable for other versions.

First thing you want to do is hit up the above web-subversion browser and find the location of the package you want. For example I was annoyed that they merged the gtk2 engines into one package and thus broke the industrial cursor theme. Well, there is a new package being developed to put the industrial theme back in, but it’s not in incoming yet. You can see similar packages here in the “New and Byhand” listing.

So you find the package you want on the SVN, now you need to download the source:

svn co svn://svn.debian.org/pkg-gnome/packages/unstable/industrial-cursor-theme ~/new

svn co invokes the subversion client to connect to the address that follows: svn.debian.org. Use the directory that applies. In this case the theme is a member of gnome, so pkg-gnome, then almost always packages/unstable/package-you-want. then ~/new will download that source to ~[home]/new, a directory called ‘new’ in your home directory. You should be fine running this as a regular user.

Now, you have the source in ~/new, what’s next? You want to go ahead and build the source into a dpkg so it will properly register in your installation and can be updated seamlessly. So, go ahead and jump to ~/new, and then dpkg-buildpackage

It may report needed dependencies and/or give errors regarding a makefile. In that case you need to root up and install the needed packages, try looking in ~/new/debian/rules file for any package you need. In my case I had to install gnome-pkg-tools.

So root down and build it, don’t give up if it has errors, look around, inspect, try to determine any other packages that may be needed that could cause errors. You may have to resign eventually if it’s just a broken package, but generally you should be able to get it built. Once you’ve done that, hop back to ~/ and you should find your shiny new .deb to dpkg -i. And you’re done, buy yourself a beer and toast to the debian developers all over the world.

To recap:

1. Locate the package in upstream subversion repository. ie, industrial-cursor-theme
2. Construct your svn command to check out the code. ie, svn co svn://svn.debian.org/pkg-gnome/packages/unstable/industrial-cursor-theme ~/new
3. Build the package from source using dpkg-buildpackage. Simply cd to the appropriate location and dpkg-buildpackage
4. Read the output. If there’s an error, look at it, stare it down. If it says something about no such directory or file, what file, what directory? Maybe you’re missing a dependency. If it’s more complicated, talking about some error in code (ie, “foo.c:38 expected ‘)'”) you may be out of luck unless you can do some coding and fix it.
5. Assuming you had no (4) or you resolved it, you’ll have a .deb file containing your package. Just dpkg -i file.deb and it will install.

Please feel free to comment if you have any questions, suggestions, clarifying points, et cetera.