Re: Small patch for more date information

will <[email protected]>
Newsgroups gmane.comp.web.pyblosxom.user
Message-ID <[email protected]>
Ummm...  I think this is a bit more accurate:

def get_ending(day):
   th_day = {"": "th", "1": "st", "2": "nd", "3": "rd"}
   if day and len(day) == 2 and day[0] == "1":
      return day + "th"

   if day and th_day.has_key(day[-1]):
      return day + th_day[day[-1]]

   return day + "th"

If you wanted, you could have this pre-calculate and then cache all the
possibilities:

endings_cache = {}

for mem in range(1, 31):
   mem = str(mem)
   endings_cache[mem] = get_ending(mem)


Anyhow, I'm not sure this really needs to be in the main base as it's
easily done as a plugin.  If there was a lot of actual call for it (i.e.
multiple people saying, "Yes--I need this.") then maybe we should toss it
in the base.  So far you're the first I know of who's interested in it.

You can model the plugin after the attached one.

/will


On Wed, 5 Nov 2003, Wari Wahab wrote:
>
> I think nthday is ugly, no offence, I guess it could be done cleaner by
> calculating what comes after a number instead.
>
> Something like:
>
> # Get the postfix of the number
> th_day = {None:'th', 1:'st', 2:'nd', 3:'rd']
> day_digit = int(self['da']) % 10
> if th_day.has_key(day_digit): day_digit = None
> self['daord'] = self['da'] + th_day[day_digit]
>
> Of course, substitude the variables to a better named one :) I can't
> seem to make any better ones.
>
> On Sat, 2003-11-01 at 12:52, Patrick Wagstrom wrote:
> > I made a small patch to pyblosxom to allow for more full date
> > information for the entires.  Namely, I wanted to get the full month
> > name and the ordinal for the day.  It's my belief that this lies more in
> > the base than in a plugin, so I put it there.
> >
> > +        nthday = ["", "1st", "2nd", "3rd", "4th", "5th", "6th" "7th", "8th", "9th", "10th",
> > +                  "11th", "12th", "13th", "14th", "15th", "16th", "17th", "18th", "19th", "20th",
> > +                  "21st", "22nd", "23rd", "24th", "25th", "26th", "27th", "28th", "29th", "30th",
> > +                  "31st"]
> > +        self['daord'] = nthday[int(self['da']) - 1][-2:]
>
> > Basically, this provides two new variables for use, $month and $daord.
> > $month is the full month name and $daord is the ordinal of the day (st,
> > dn, rd, th).  Mainly I wanted them to make the reported days look a
> > little nicer.  This doesn't change any of the URL stuff.  Anyone know of
> > a better way to do the ordinal stuff?  Perl has a nice %o modifier, that
> > python doesn't seem to have.
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive?  Does it
> help you create better code?   SHARE THE LOVE, and help us help
> YOU!  Click Here: http://sourceforge.net/donate/
> _______________________________________________
> pyblosxom-users mailing list
> pyblosxom-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
> https://lists.sourceforge.net/lists/listinfo/pyblosxom-users
>

-- 
whatever it is, you can find it at http://www.bluesock.org/~willg/
except Will--you can only see him in real life.
title.py (text/plain, 729 B)
"""
Provides me with a $urlencodedtitle which is better for the Google link.
It's a urlencoded title.

This is provided with no warranty whatsoever.  Use it at your
own risk.

Copyright 2002, 2003 Will Guaraldi

Revisions:
1.0 - created
"""
__author__ = "Will Guaraldi - willg at bluesock dot org"
__version__ = "1.0"
__url__ = "http://www.bluesock.org/~willg/pyblosxom/"

import urllib

def cb_story(args):
    """
    This method gets called in the cb_story callback.  Refer to
    the documentation for that.
    """
    entry = args["entry"]

    if not entry.has_key("title"):
        entry["urlencodedtitle"] = "N/A"
        return

    entry["urlencodedtitle"] = urllib.quote(entry["title"])
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.