Tiny Tiny RSS: Community

Af_comics: filter that changes date

Hi,

I wrote a little filter for af_comics for this feed: https://www.stuttmann-karikaturen.de/feed.rss

Additionally to showing the full-res image I’d also like to add the date from the title as updated tag, as the feed doesn’t provide it.
Is there any way to add the date in an af_comics filter?

Like $article["updated"] = date()->format("r"); or so?

i don’t have the code in front of me right now but this could probably work, i think entire article object is passed to the plugin and almost everything could be modified (except for GUID).

Alright, so I got the right idea. :slight_smile:
Could you point out which datetime format has to be provided? Unix timestamp? ISO 8601 (e.g. 2004-02-12T15:19:21+00:00)? Something else?

most likely this should be something strtotime() would understand.

It seems to work, however doesn’t seem to really change the date of the article:

[23:36:43/7669] force catchup: 
[23:36:43/7669] base guid found, checking for user record
...
[23:36:43/7669] guid 2,https://www.stuttmann-karikaturen.de/karikatur/7180 / SHA1:141108b33c829ffd3e8ec17b1c11aa9563134af3
[23:36:43/7669] orig date: 
[23:36:43/7669] date 1568072203 [2019/09/09 23:36:43]
[23:36:43/7669] title Unendliche Geschicht: Zweikampf im Boxen  (08.09.2019)
...
[23:36:43/7669] ... Af_Comics
Array
(
    [owner_uid] => 2
    [guid] => 2,https://www.stuttmann-karikaturen.de/karikatur/7180
    [guid_hashed] => SHA1:141108b33c829ffd3e8ec17b1c11aa9563134af3
    [title] => Unendliche Geschicht: Zweikampf im Boxen  (08.09.2019)
    [content] => 

Themen: Downing Street, England, Brexit, EU, EU-Austritt, House of Parliament, London, Parlament, Premier, Referendum, Großbritannien, Nationalismus, Rechtspopulisten, Volksabstimmung, Zerfall, Boxen, Demokratie, EU/Europa, Sport
Personen: Boris Johnson

    [link] => https://www.stuttmann-karikaturen.de/karikatur/7180
    [labels] => Array
        (
        )

    [tags] => Array
        (
        )

    [author] => 
    [force_catchup] => 
    [score_modifier] => 0
    [language] => de
    [num_comments] => 0
    [feed] => Array
        (
            [id] => 140
            [fetch_url] => https://www.stuttmann-karikaturen.de/feed.rss
            [site_url] => https://www.stuttmann-karikaturen.de
            [cache_images] => 0
        )

    [updated] => 08.09.2019
)
[23:36:43/7669] === 0.0000 (sec)

Above trace shows a print_r($article). the $article[updated] is set correctly. However, orig date is still empty.

Any way to alter orig date?

looks like updated is not passed to plugins, i’ll make a note to fix this.

i haven’t tested it but it should probably work: https://git.tt-rss.org/fox/tt-rss/commit/94a12b9674ac3ce22c1f444f097892d6295f52dc

output timestamp format should match input format.

Thanks a lot for the fast response!

This works now:
$article["timestamp"] = "2018/03/08 09:12:17";
Nice! :slight_smile:

However, I noticed that the debug message happens to be the old date, as it is logged before the variable is overwritten. Could be confusing.
[10:45:33/12705] date 1568198733 [2019/09/11 10:45:33]

Maybe a solution would be to not overwrite entry_timestamp_fmt, but entry_timestamp? That way one would have to use either $article["pubDate"] or $article["updated"], depending on being RSS or Atom. The benefit would be, that the date format wouldn’t be so strict, as strtotime() is used.

rss feeds can pass timestamp in various random (and broken) formats, i think it would be unfair to force plugins to deal with this bullshit, additionally i think tt-rss parser abstracts those xml fields away.

i thought about passing unformatted timestamp to plugins and formatting it later but it’s not like this makes a lot of difference in the end.

i agree that the debugging output message should be moved though.

e: maybe we should pass entry_timestamp to plugin, as received from the parser, and the error handling block for invalid/unparsed timestamps and formatting should be moved below plugin hook handler. this way it would be harder for a misbehaving plugin to break feed updates by passing an invalid timestamp and causing an exception on INSERT, etc.

how about this instead? https://git.tt-rss.org/fox/tt-rss/commit/b0d67cd3d0f68650cdc6b73f3e76c3ca5936225b

i think this would pass unixtime to plugins. it’s not as flexible as something strtotime() would happily eat but at least it would be harder to break, and slightly easier to modify / generate for plugins.

Looks absolutely perfect to me.

Using unix timestamps seems very reasonable as de facto standard.
The refactoring also fixes the debug messages. I’ve tested it.

Awesome!! :partying_face: