[Tutor] Assistance request when using python 'calendar'

o1bigtenor o1bigtenor at gmail.com
Tue Aug 4 17:39:37 EDT 2020


On Tue, Aug 4, 2020 at 12:40 PM Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>
> On Fri, 31 Jul 2020 11:56:29 -0500, o1bigtenor <o1bigtenor at gmail.com>
> declaimed the following:
>
>         Interesting -- according to the date stamp it took four days for this
> to propagate up to gmane's mirror of the Tutor list. Your other posts on
> comp.lang.python showed up almost immediately.
>
> >I regularly work in planning through multiple years at once.
> >This means that I like to have a lot of stuff available in a calendar
> >function.
> >Python seems to be locked when I need to display more than 1 year at a
> >time.
> >
> >I don't see a way to display something like 3 years worth of calendar
> >starting at a point 23 months from now.
> >(I see how to display 1 year at a time but not multiple years.)
> >
>
>         Bottom up: Multiple (Jan-Dec) years is done by looping once for each
> year and combining the returned data yourself.
>
>         For arbitrary start/end months you will have to loop asking for each
> month, and you will have to combine that data into whatever structure makes
> it suitable for your output criteria.
>
>         My suggestion (carried over from comp.lang.python) is to use the HTML
> calendar class. Each month is generated as an HTML table, and it is easy to
> wrap multiple month tables as cells in a larger table structure. Then use a
> web browser to view the end result -- the browser even allows horizontal
> scrolling if the calendar is wider than the browser window).

Very interesting, a program from the mid 1980's called 'cal' is far
more flexible
and productive.

Sorry - - - - the assumption seems to be that this is an occasional
kind of thing.

Over the weekend (a long weekend here) I actually had to use 3 different
iterations of the calendar. It is not uncommon in this task to need to work for
over much more than 3 years. As the present iteration only works from today's
date as soon as the time frame stumbles forward the calendar must needs
be extended.
The solutions presented seem to infer that the request is somewhat static.
If the entire code base needs to be rewritten each time the span of years
desired changes then the tool is obstructing the work rather than assisting in
that work's completion. So HTML isn't going to help much. Great idea for
a static calendar but likely not as good for a flexible one.
>
> >Is there a way to do this?
>
>         This appears to be a feature request -- in that you are dissatisfied by
> the calendar module as it exists. You haven't shown any code attempting to
> develop your solution, nor any exploration of outside sources.
>
>         One of the first things that showed up on Google search is:
> https://www.freecodecamp.org/news/introducing-timeboard-a-python-business-calendar-package-a2335898c697/
> Which may be too specific to job scheduling...

There are ideas present in said example but it might be easier to re-write
perl code written by a now deceased mentor/friend where that code got most
of the job done but there are some things that need changing and a few bits
of the visuals I desire to change.

I have been looking for about 4 years for software usable over a period of at
least 2 years. Had found 'cal' but was frustrated that I could only get a
display of 3 months in width no matter what terminal screen column count
was available because the 80 x 25 terminal is hard wired into 'cal'. So I was
looking at how to misdirect cal into believing that it could write to a 220+
column wide terminal. That would have given me the flexibility in use and
most of the features I needed. In retrospect maybe I had complained a few
too many times about hard limits in programs carrying over some almost 40
years and so it was quite to my surprise when my friend sent me a few pages
of source code and said - - - - try it, tell me what doesn't work. So the last
version I received was about the 6th (IIRC). This was something he worked
on sporadically likely as much for amusement as for the pleasure of doing it.
We traded ideas and concepts in a very very large variety of areas and with
spring approaching we both got busy with other ideas and projects. He was
not able to complete the program.
>
> https://www.guru99.com/calendar-in-python.html
> https://pymotw.com/2/calendar/ are tutorials of the standard calendar
> module. As stated in the second link
> """
> If you need to produce output in a format other than one of the available
> defaults, you can use calendar to calculate the dates and organize the
> values into week and month ranges, then iterate over the result yourself.
> The weekheader(), monthcalendar(), and yeardays2calendar() methods of
> Calendar are especially useful for that sort of work.
> """

The second of the above examples has some ideas which need to be
extended to get closer to what I need.
My research has shown that week numbers is something that is actually
quite a foreign concept in many cultures as this just isn't the way things
are done. Except - - - - - if I give you a date and ask you for the date
some 45 days before and 105 days after - - - - well that's another program
and some computations and then when I ask you for the next date - - - -
well that's taking a lot of time. If I ask you for the date 6 weeks and 3 days
before x and the date 15 weeks later you go to your trusty - - - - not yours
but mine - - - - calendar with the week numbers  and most anyone can
take a week number and subtract 6 (and three days please) and add
15 to the week number. No programming and very very simple steps.

>
> https://github.com/llazzaro/django-scheduler is for the Django
> web-application framework
>
There are LOTS of calendars like that out there. They mostly all have one
huge limitation - - - - they work within one (1) year - - - so when you need
2.5 to 3 - - - - better luck next time - - - - and yes I've looked. Installed I
don't know how many business/project management programs and its
one of the common joys - - - - as soon as you want to look at a calendar
over more than one years time - - - highly unlikely.
>
>         I would also point out that the calendar module is in the Python
> library directory, and is a Python source code file (not some compiled
> C-language extension), so you can readily study it to work out potential
> subclassing. In particular, you may wish to study the .formatyear() methods
> of the text and HTML classes.

I have spent some time looking for 'official' Python information on sub-classes
and their development. Found nothing to date but have only spent some 45
minutes so maybe with more time some to be found - - - maybe.

>
>         Even if you manage to create a subclass which can take a start
> year/month and an end year/month, take note that you have no ability to
> annotate this data; that is, you can not mark specific dates as having some
> event happen on that date. The best you could do is generate an HTML output
> and later edit the cells of the HTML tables to contain your annotations. If
> you intend to create a full "business planning" application you'll have to
> extend calendar to work with something that can hold the annotations
> between sessions (save/load logic), probably using raw datetime objects for
> each day, and modifying/subclassing calendar so that it can use the
> datetime object embedded in your data to determine where to place it on the
> output calendar.
>
Much work to be done and it is ever so fascinating to see how prevalent
business thinking is confined into small time frames. But then business is
primarily worried about profitability per quarter - - - - - well that
is what the
senior staff earn their bonuses on - - - - but here - - -  I really do need to
work across at least 3 and preferably even 5 years but that's considered
to be a corner case - - - - .

Thanks for the ideas.


More information about the Tutor mailing list