Display the last post time for a list or all lists.
Does Mailman 3 have something similar to https://www.msapiro.net/scripts/last_post.py displaying the last post time for a list or all lists?
On 02/21/2018 05:00 AM, Henrik Rasmussen wrote:
Does Mailman 3 have something similar to https://www.msapiro.net/scripts/last_post.py displaying the last post time for a list or all lists?
It wouldn't be difficult to do, but at the moment, it wouldn't provide anything useful because of <https://gitlab.com/mailman/mailman/issues/453>.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mark Sapiro wrote:
It wouldn't be difficult to do, but at the moment, it wouldn't provide anything useful because of <https://gitlab.com/mailman/mailman/issues/453>.
The issue is now fixed in the branch head at least. The script corresponding to https://www.msapiro.net/scripts/last_post.py would be almost identical except for changing real_name to display_name, last_post_time to last_post_at and fixing the print for Python 3. Also changing the string interpolation to format(), it becomes:
import time
def last_post(mlist): print('{}: Last post at {}'.format( mlist.display_name, time.ctime(mlist.last_post_at) ))
The only issue with the script is for a list which has had no posts since #453 was fixed, mlist.last_post_at is None and time.ctime(None) is the current date and time.
That too could easily be fixed like:
import time
def last_post(mlist): if mlist.last_post_at: print('{}: Last post at {}'.format( mlist.display_name, time.ctime(mlist.last_post_at) )) else: print('{}: No posts'.format(mlist.display_name))
The trickier part is the Mailman 3 mailman withlist command has no option to run for all lists, so you'd need to run it something like
#!/bin/sh
for list in mailman lists -q
; do
mailman withlist -r last_post -l $list
done
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
On 03/01/2018 07:15 PM, Mark Sapiro wrote:
The issue is now fixed in the branch head at least. The script corresponding to https://www.msapiro.net/scripts/last_post.py would be almost identical except for changing real_name to display_name, last_post_time to last_post_at and fixing the print for Python 3. Also changing the string interpolation to format(), it becomes: ...
For the archive, in the prior post in the Hyperkitty archive, all the indentation in the Python code and shell script was lost. It was OK in the posts as delivered to list members, but if you are reading the archive, you'll have to figure it out. The shell script will work anyway, but not the Python.
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
since #453 was fixed, mlist.last_post_at is None and time.ctime(None) is the current date and time. That too could easily be fixed like:
import time def last_post(mlist): if mlist.last_post_at: print('{}: Last post at {}'.format( mlist.display_name, time.ctime(mlist.last_post_at) )) else: print('{}: No posts'.format(mlist.display_name)) The trickier part is the Mailman 3 mailman withlist command has no option to run for all lists, so you'd need to run it something like #!/bin/sh for list in mailman lists -q; do mailman withlist -r last_post -l $list done
Thanks for the leg up on converting that from mailman2 to mailman3 much appreciated.
I found 1 issue. When I had a list that was imported, but had not done another post after being imported, the script would fail with the following error: print('{}: Last post at {}'.format( mlist.display_name, time.ctime(mlist.last_post_at) )) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: 'datetime.datetime' object cannot be interpreted as an integer
Made a final change to set the mlist.last_post_at to mlist.last_post_at.timestamp() and that cleared the problem.
The final form of last_post.py is:
import time
def last_post(mlist): if mlist.last_post_at: print('{}: Last post at {}'.format( mlist.display_name, time.ctime(mlist.last_post_at.timestamp()) )) else: print('{}: No posts'.format(mlist.display_name))
Don't know if this will help others, but the place I put the last_post.py file was in: /opt/mailman/venv/bin (same location as the mailman script executable).
Bryan
participants (3)
-
bryant@sandiego.edu
-
Henrik Rasmussen
-
Mark Sapiro