I want to automate counting the number of blogposts I post in a week. Am assuming that the likeliest way of doing that is parsing the RSS feed for timestamps, and count them that way. Do you have any pointers to where such a RSS parser script (for Mac or MAMP) might be found?

9 reactions on “

  1. Thank you Peter! That’s precisely what I need. I’ll dig through those statements to understand what the code does and learn from it.

    Yes, the limitation is the length of the feed itself (set to 15). Which is ok. One could adjust the frequency of running the script (and store previous results) to take that into account if the number of posts in a week goes up to that limit.

  2. Out of curiosity I tried it with my own feed on my Mac but I constantly get the error

    Failed conversion of “$line” using format “%a, %d %b %Y %T %z”
    date: illegal time format

    I am reading up on the date man-pages but I can’t see where to pinpoint the problem. I have a suspicion it might be something with single/double quotes but I can’t quite find the bug…

    • I got this error a lot when I was hacking this together: the cause is a mismatch between the date format in your RSS feed and the date format in the format string in the script.

      When I run the script on your RSS feed (which I assume is http://diggingthedigital.com/feed.xml), it works for me:

      curl -s http://diggingthedigital.com/feed.xml | \
      > grep pubDate | \
      > sed -e ‘s///g’ | \
      > sed -e ‘s///g’ | \
      > while read -r line ; do
      > date -j -f “%a, %d %b %Y %T %z” “$line” “+%V”
      > done | \
      > sort -n | \
      > uniq -c
      4 22
      3 23
      3 25

      …so I suspect there’s a different between the date command on your machine and the date command on my machine.

      Try:

      date +”%a, %d %b %Y %T %z”

      and see what that outputs. On my machine it produces:

      Wed, 20 Jun 2018 17:30:58 -0300

      which matches the date format in your RSS feed, which, for example, is:

      Mon, 28 May 2018 10:26:32 +0200

      I wonder if this could also be due to language mismatch — i.e. if the language in your shell is Dutch and the language of your RSS feed date is English (this is just a guess).

      • Getting the same errors as Frank. I do have a Dutch language Mac, and English feed. Will explore.

    • Yes there is Peter, it’s one of the settings in Jetpack. But as I am having trouble using Jetpack (because of xmlrpc being disabled by my hoster), I can’t just switch it on (gets an error upon saving). I am now trying to find out where in the wp_options table this is stored in the WordPress database, so I can set it directly in the database.

Comments are closed.

    Mentions

  • 💬 Peter Rukavina