anglewf
anglewf

Reputation: 1

How to have a calendar show a week out of the month then the next week appears? This is for a e-paper display using google calendars

We are trying to show a calendar on a e-ink display linked to a google calendar. We can get the whole month to display, but we want just one week to display at a time and when the week ends, it will change the week that has passed to the following week.

We have tried to create loops using "if" and "else", but we have not been able to get it to run correctly with those yet.

positions = {
    # positions the code block to appear on certain columns and rows
    'a1': (col1, row1), 'a2': (col2, row1), 'a3': (col3, row1), 'a4': (col4, row1),
    'a5': (col5, row1), 'a6': (col6, row1), 'a7': (col7, row1),

    'b1': (col1, row2), 'b2': (col2, row2), 'b3': (col3, row2), 'b4': (col4, row2),
    'b5': (col5, row2), 'b6': (col6, row2), 'b7': (col7, row2),

    'c1': (col1, row3), 'c2': (col2, row3), 'c3': (col3, row3), 'c4': (col4, row3),
    'c5': (col5, row3), 'c6': (col6, row3), 'c7': (col7, row3),

    'd1': (col1, row4), 'd2': (col2, row4), 'd3': (col3, row4), 'd4': (col4, row4),
    'd5': (col5, row4), 'd6': (col6, row4), 'd7': (col7, row4),

    'e1': (col1, row5), 'e2': (col2, row5), 'e3': (col3, row5), 'e4': (col4, row5),
    'e5': (col5, row5), 'e6': (col6, row5), 'e7': (col7, row5),

    'f1': (col1, row6), 'f2': (col2, row6), 'f3': (col3, row6), 'f4': (col4, row6),
    'f5': (col5, row6), 'f6': (col6, row6), 'f7': (col7, row6)
    }

This is from another .py file that calls the positions.

"""Using the built-in calendar function, draw icons for each number of the month (1,2,3,...28,29,30)""" cal = calendar.monthcalendar(time.year, time.month)

        while True:

            if numbers in cal[0]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['a'+str(cal[0].index(numbers)+1)])
            elif numbers in cal[1]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['b'+str(cal[1].index(numbers)+1)])
            elif numbers in cal[2]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['c'+str(cal[2].index(numbers)+1)])
            elif numbers in cal[3]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['d'+str(cal[3].index(numbers)+1)])
            elif numbers in cal[4]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['e'+str(cal[4].index(numbers)+1)])
            elif len(cal) is 6:
                break
            else numbers in cal[5]:
                image.paste(im_open(dpath+str(numbers)+'.jpeg'), positions['f'+str(cal[5].index(numbers)+1)])

We expect it to show for example, Monday 2 through Sunday 8 and then change to Monday 9 through Sunday 16 when the date changes from the 8th to the 9th. Our actual results so far are either the whole month shows or a week shows, but it may show the wrong week and/or does not change when the week is up.

Upvotes: 0

Views: 31

Answers (0)

Related Questions