INFORMATION FOR WRITING NEW FEEDERS
A new feeder framework have been written which should make it easier for you to write feeders for your favourite news-source(s). You are very much encouraged to write such gems, and you are even more encouraged to send them to simon.kagstrom.864@NOSPAMMINGstudent.lu.se afterwards :-)
BACKGROUND
The feeders fetch news from the WWW (or other sources?) by using lynx (other programs possible in theory) and parsing the dumped file, outputting it to a (by the ttnews-program) readable format. The fetching of the news and the parsing is separated from each other, and you should only write the parsing.
PARSING FORMAT
The format ttnews likes (and demands) is the following:
NEWSSOURCE:The name of the news source
...
DATE:Date of Article
TIME:Time of Article
TITLE:Title of article
COLOUR:text colour to display in
URL:Url of related information
IMAGE:Image file that may be displayed
TEXT:
...
TEXT:
The NEWSSOURCE:-part tells from where the news comes. This is only needed once (first line) in the file, but can be placed among the articles if they come from diffrent sources (unlikely...).
A DATE: line makes a new article. Only DATE is mandatory. Of course, you'll have to remove the "Date of Article" parts, but I guess that's obvious A typical news item could look like the following:
DATE:1999-10-08
TIME:17:06
TITLE:Motsägelsefulla rapporter från Tjetjenien TEXT:Federala ryska styrkor och tjetjenska förband drabbade på fredagen samman norr om Terekfloden med vilken Ryssland försöker spärra av en tredjedel av utbrytarrepubliken och upprätta en "befriad zon". (TT)
Several TEXT: sections can be used to separate paragraphs, the above example uses only one paragraph. (And it's in Swedish, but this it was the most "clean" example I could find).
WRITING YOUR OWN FEEDER
Now, after this short introduction, don't you feel like writing a feeder of your own? I bet. Well it's easy. You basically need to implement TWO(!) methods (functions) of your own, and do some administrative work besides.
The idea is as follows: fetchNews.cpp is a class for fetching the news. It calls methods (functions) from a class named ReadNews, which is defined in readNews.h. You need to care about two things (and cut and paste a third).
First, you must implement the method
QString ReadNews::getForkCommand()
Which does only one thing, namely it returns a string with the command that shall be executed by the program. For the tt-feeder (tt.cpp) it looks like the following:
QString ReadNews::getForkCommand()
{
return "lynx -reload -width 1000 -dump -nolist http://www.torget.se/v2/tt";
}
lynx reads a fresh version of the page, dumps the output (like seen in lynx) using the specified width (high number good, as it keeps paragraphs on single lines.
The second part is the "difficult" one. You now need to implement the method
int ReadNews::generateNewsfile()
which reads from inFile does the actual parsing and outputs to the file outFile. inFile and outFile are defined in readNews.h and should be assigned their filenames in the constructor. This method returns 0 if it was executed without trouble, and another value otherwise.
Your file should be named an appropriate name, like slashdot.cpp for the slashdot feeder. It should include readNews.h, and implement the methods defined in readNews.h. You're in for some cut and paste in other words.
Finally, you are to compile your feeder. Open up the Makefile and add the following (albeit custiomized to fit your needs)
bbc: fetchNews.o bbc.o
$(SYSCONF_LINK) $(LFLAGS) -o bbcServer bbc.o fetchNews.o $(LIBS)
This, of course, is an example for bbc, and it links fetchNews.o with bbc.o, and outputs to the binary bbcServer. As you might see, this is a linking trick, probably not entierly good for object orientation purposes, but it works and makes the feeders easy to write.
SOME THINGS ABOUT PROGRAMMING STYLE
Ok, I know that this is a bit overkill for such a small project, but I have a few guidelines for the look of this code.
The code is written using java-like naming conventions, i.e you name a method
readNews(...)
and NOT
read_news(...)
Why? Well, because I think it looks better that way. Furthermore, you
should keep the convention of giving classes a Capital First Letter, and
naming methods (functions) and attributes (variables) with a small first
letter.
The filenames should be the same as for the classes they contain (with a small first letter, however). I.e the class FetchNews is called fetchNews.cpp and fetchNews.h on disk. Use at most one public class in each file.
CONTACT
Simon Kågström, simon.kagstrom.864@NOSPAMMINGstudent.lu.se
