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?
Here’s a shell script (which I’ve only tested on a Mac) that will output the number of posts per week number:
https://gist.github.com/reinvented/23af9f7503d293a79f078f61da8d914e
Its output look like this (right now, in June 2018):
6 23
6 24
3 25
There were 6 posts in week 23, 6 posts in week 24, and 3 posts so far in week 25.
The limitation is that the counting only goes as far back as the number of posts in your RSS feed.
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.
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.
I’ve updated the script (https://gist.github.com/reinvented/23af9f7503d293a79f078f61da8d914e) to temporarily switch Bash to using English, run, and then switch back to Dutch.
Feature request: if there’s a way to have WordPress accept [Markdown](https://en.wikipedia.org/wiki/Markdown) in comments, that would be very helpful when sharing bits of code, especially. I’ve just enable this for comments on [my blog](https://ruk.ca/), via the [Markdown module](https://www.drupal.org/project/markdown).
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.