Alternative method of testing for unread feeds

Development-related discussion, including bundled plugins
DieKatzchen
Bear Rating Trainee
Bear Rating Trainee
Posts: 14
Joined: 06 May 2013, 20:39

Alternative method of testing for unread feeds

Postby DieKatzchen » 20 Jul 2013, 23:05

I want to make a plugin that adds another checkbox to the per-feed settings that lets me use an alternative method for testing if a feed has updated, and then marking as unread. This is primarily for Fanfiction.net which marks an article(fic) as updated whenever there is a new chapter. This would be fine, except it also updates the article with the number of reviews a story has every time someone leaves a review. Needless to say, this gives "Mark updated as unread" fits. My solution to this is to compare only the <updated> tag. I should warn you all that this is my first time writing PHP, so I may ask some stupid questions.

My first question is if anyone knows of any plugins that might be relevant for me to look at and base this plugin on. If not, do I want to hook the update process or the feed parsing process?

DieKatzchen
Bear Rating Trainee
Bear Rating Trainee
Posts: 14
Joined: 06 May 2013, 20:39

Re: Alternative method of testing for unread feeds

Postby DieKatzchen » 21 Jul 2013, 20:13

Here's what I have so far. Any feedback?

Code: Select all

<?php
class Alt_Update extends Plugin {

   private $host;
   
   function about() {
      return array(1.0,
         "Compares the <updated> tag on FF.net to determine if article has updated, and marks it as unread.",
         "DieKatzchen");
   }
   
   function init($host) {
      $this->host = $host;

      $host->add_hook($host::HOOK_FEED_PARSED, $this);
   }
   
   function hook_feed_parsed($article) {
      $owner_uid = $article["owner_uid"];

      if (strpos($article["link"], "fanfiction.net")) {  //checks if feed is FF.net feed, would much rather have a per-feed checkbox.
         if (strpos($article["plugin_data"], "fanfiction,$owner_uid:") === FALSE) {  //Copied from article filter.  Do I need it?

            if ($debug_enabled) {
               _debug("Alt_Update: Processing feed");
            }
            
            $doc = new DOMDocument();
            $doc->loadHTML(fetch_file_contents($article["link"]));
            
            if ($doc) {
               $xpath = new DOMXPath($doc);
               $entries = $xpath->query(entry/updated);

               foreach ($entries as $entry) {
                  /*  Compare new value to old value, than mark
                  //  as new if newer
                  */
               }
            }
         }
      }
   }
}
?>

feader
Bear Rating Master
Bear Rating Master
Posts: 160
Joined: 26 Dec 2012, 20:03

Re: Alternative method of testing for unread feeds

Postby feader » 21 Jul 2013, 21:20

DieKatzchen wrote:Here's what I have so far. Any feedback?
[…]


I don't get what you want to achieve with your code. From what I read, you want TTRSS to not interpret some updates to articles in the feed FF.net as updates. Alas I don't know anything about this mechanism, and so can't point you to the right direction, but your code has some serious flaws:

    In other plugins I have seen, the code

    Code: Select all

    strpos($article["plugin_data"], "fanfiction,$owner_uid:") === FALSE

    is intended to assure that the plugin does its magic only once. E.g. af_feedmod uses it to load an article only once, in order to reduce network traffic. AFAIU that would not suit your needs at all because there may be multiple updates to articles, but I may be wrong about that.

    HOOK_FEED_PARSED is called every time the feed was fetched and parsed, so fetching an entire web page at this stage would be quite resource intensive if not checked with a stopper as described above. By the way, AFAIK you will have to work to get your stopper in the DB, at least for the first time.

    Your xpath (should be in quotes BTW, and is probably missing a // and other things) looks a bit strange. You want to query on the web page or on the feed or what?

So first, you should try to clarify what you actually need to achieve. Is it sufficient to manipulate the feed data, or do you have to manipulate data structures of TTRSS?
Otherwise you do the right thing: Trying to work yourself from the back end to the front end, GUI integration is the last thing to do. I wish you good luck with it.

DieKatzchen
Bear Rating Trainee
Bear Rating Trainee
Posts: 14
Joined: 06 May 2013, 20:39

Re: Alternative method of testing for unread feeds

Postby DieKatzchen » 21 Jul 2013, 22:19

What I am trying to do is this. Every time a feed is updated this plugin checks if it's supposed to run (if the checkbox has been checked), then goes through for each entry in the feed and compares the value of the <updated> tag to see if it has changed and marks it as unread if it has. In other words, when the feed is updated:

Code: Select all

if (enabled for this feed) {
    for each (entry in feed)
        if ((new value of <updated>) != (old value of updated))
            Mark as unread
}


Thus I'm not so much causing it to not see some articles as updated, as I am marking updated feeds as unread - but only if they've updated in a specific way. Does that make more sense?

This is all because FF.net is stupid and puts the number of comments on the story directly in the story's feed entry, causing TTRSS to see it as updated every time someone leaves a comment.

Should I be hooking somewhere else? And I couldn't seem to find a set_Unread() anywhere, so I think I'm going to have to manually mess with the database, so please tell me I only missed it.

feader wrote:In other plugins I have seen, the code

Code: Select all

strpos($article["plugin_data"], "fanfiction,$owner_uid:") === FALSE

is intended to assure that the plugin does its magic only once. E.g. af_feedmod uses it to load an article only once, in order to reduce network traffic. AFAIU that would not suit your needs at all because there may be multiple updates to articles, but I may be wrong about that.

HOOK_FEED_PARSED is called every time the feed was fetched and parsed, so fetching an entire web page at this stage would be quite resource intensive if not checked with a stopper as described above. By the way, AFAIK you will have to work to get your stopper in the DB, at least for the first time.

If that's what it's doing, then you're right, I don't need it. I'm only comparing one node of the feed. I just sort of blindly copied some of that code so I think I need to remove the part about the DOMDocument, right?

feader wrote:Your xpath (should be in quotes BTW, and is probably missing a // and other things) looks a bit strange. You want to query on the web page or on the feed or what?

I'm looking for all the <updated> that are the children of <entry> in the feed. I could use query("//updated") except that there's an <updated> in the root node that I don't want.

feader
Bear Rating Master
Bear Rating Master
Posts: 160
Joined: 26 Dec 2012, 20:03

Re: Alternative method of testing for unread feeds

Postby feader » 22 Jul 2013, 11:38

DieKatzchen wrote:What I am trying to do is this. […] Does that make more sense?

Yes, although this is still fluffy talk since you still haven't mentioned what you want to change in TTRSS.

DieKatzchen wrote:This is all because FF.net is stupid and puts the number of comments on the story directly in the story's feed entry, causing TTRSS to see it as updated every time someone leaves a comment.

If that is your problem, you can try to use other plugins to remove the number of comments from the feed entries, like ff_FeedCleaner.

DieKatzchen
Bear Rating Trainee
Bear Rating Trainee
Posts: 14
Joined: 06 May 2013, 20:39

Re: Alternative method of testing for unread feeds

Postby DieKatzchen » 22 Jul 2013, 19:18

feader wrote:If that is your problem, you can try to use other plugins to remove the number of comments from the feed entries, like ff_FeedCleaner.


Thanks, that worked. I may still finish this plugin just because I can, but at least it's no longer bugging me with erroneous updates.


Return to “Development”

Who is online

Users browsing this forum: No registered users and 4 guests