Creating a Planet Me Blog Aggregator
Now you need to have the Planet code run to aggregate blogs, and make it easy to modify the list of blogs to aggregate.
You can solve the regular aggregation by using cron. Listing 5 shows how to have Planet Me updated every night.
Listing 5. Set Up a cron Job to Aggregate Blogs
$ mkdir -p ~/mycron $ cd ~/mycron $ vi upd-planet.sh #!/bin/sh cd ~/planet; http_proxy=http://dairiserver:3128/ \ python planet.py me-meta/config.ini $ chmod +x upd-planet.sh $ echo \ '00 04 * * * /home/ben/mycron/upd-planet.sh' \ >|upd-planet.cron # only if you already use cron from outside ~/mycron $ crontab -l >|oldcrontab.cron $ cat *.cron >|newtab $ crontab newtab $ rm -f oldcrontab.cron
It is easy to add and remove blogs if you keep a list of blog definition files instead of trying to manage the configuration file itself manually. You can use the generate-config script shown in Listing 6 to move the blog name and URLs into very simple files in a blog subdirectory.
You can use a file manager or the command line to add or remove files that determine the configuration of your aggregation scheme. This also paves the way for a simple Firefox extension to allow new RSS feeds to be added to Planet Me from a context menu. Handling archives as shown later is also simplified by moving the blog information out of config.ini.
Listing 6. Generate files to define the blogs to aggregate.
$ cd ~/planet/me-meta $ mv config.ini config.ini.template $ edit config.ini.template # remove all blog URL sections from the bottom of file # search for http: to find the first one $ mkdir blogs $ echo http://rss.slashdot.org/Slashdot/slashdot \ >blogs/slashdot.blog $ ./generate-config
Listing 7. Use the files to create a blog aggregation configuration.
#!/bin/sh cp -av config.ini.template config.ini for if in blogs/*.blog do base=$(basename $if .blog); content=$(cat $if); echo "" >> config.ini echo "[$content]" >> config.ini echo "name = $base" >> config.ini echo "face = $base.png" >> config.ini done
The two files that control how your planet will look are me-meta/index.html.tmpl, which is the template for the page content, and me/planet.css, which is the cascading stylesheet.
By default, the face, entry, date and sidebar all define styles that can be changed using the stylesheet. You can use custom fonts by modifying the font-family CSS tag.
The index.html.tmpl template has extra tags that the Planet code uses to generate the final index.html file. The main tags of interest are TMPL_LOOP, TMPL_IF and TMPL_VAR. The news feeds are placed into the output page using the <TMPL_LOOP Items> HTML-like tag and its corresponding close tag. The HTML elements between these two tags will be output once for each news item to be displayed. These elements define what and how output is generated for each news item.
The Planet code uses these variables to get at the news feed content. For example, it replaces the <TMPL_VAR title> tag with the actual title of the current news item. Note that TMPL_VAR doesn't have a corresponding close tag.
The TMPL_IF tag is used to check whether information exists or to set specific conditions. For example, sometimes news items do not have title information. The code in Listing 8 will output title information if it exists, and output nothing if a title does not exist. The escape attribute on the TMPL_VAR tag tells Planet to make sure that the value of the link variable is in a form that is a legal HTML attribute.
Listing 8. Set conditions for your output with the TMPL_IF tag.
<TMPL_IF title> <a href="<TMPL_VAR link ESCAPE="HTML">"> <TMPL_VAR title> </a> </TMPL_IF>
You'll have to edit both the me-meta/index.html.tmpl and CSS files to move the channel icon to the left of the news item with Planet Me.
By default, your index.html.tmpl will display the channel icon only when the current news item is from a different channel than the one preceding it.
I've removed the <TMPL_IF new_channel> tags from around the outputting of the face image information in the fragment of index.html.tmpl shown in Listing 9. I also used a CSS class of news-item-icon for the channel image and news-item for the main news post section and a new class of embedded-face for the actual channel image.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Sony Settles in Linux Battle
- Libarchive Security Flaw Discovered
- Profiles and RC Files
- Maru OS Brings Debian to Your Phone
- The Giant Zero, Part 0.x
- Snappy Moves to New Platforms
- Understanding Ceph and Its Place in the Market
- Git 2.9 Released
- Astronomy for KDE
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide