Skip to main content

Python script - pop-up reminder based on data from Excel



Completion date: December 17, 2018

Changes to the script (Dec 14 2018):

1. Used Date format to compare dates. 

2. Show message for update AR if the date is overdue and due today.

Changes to the script (Dec 17 2018):

1. Corrected the ws.max_row+1 to ws.max_row.

2. Changed to loop from bottom up (so the the newest records gets checked first)

=========== The script ===========
#! python3 -- Modified on Dec 17 2018
import openpyxl
import tkinter.messagebox
from datetime import date
import os

#Get the workbook, worksheet
file = "AR.xlsx"
wb = openpyxl.load_workbook(file)
ws = wb['Sheet1']

#Iterate through the rows of column "Next update on" = Column D = 4, from bottom up (the newest record to oldest)
for i in range(ws.max_row, 2, -1):
    next_update_datetime = ws.cell(row=i, column=4).value
    if (next_update_datetime is not None):
        #convert to date
        next_update_date = next_update_datetime.date()

    #Check if any AR is due or overdue for update
    if next_update_date <= date.today():
        result = tkinter.messagebox.askquestion("AR Progress Update Reminder", "You need to update AR today.  Would you like to open the workbook?", icon='question')
        if result == 'yes':
            os.startfile(file)
            break
        else:
            break
=========== End of script ===========


Completion date: December 7, 2018

It has been a while since my last invention stories.  Last week, I have created something using Python programming language.

My application is a simple script that checks if anything are due for update on the day.  I have configured it to run automatically on each Windows startup (I turn off my notebook every day after work).  It is to help my work on chasing the accounts receivables, as I realize I might forget to update since it is not a daily chore.  So, the program would check if I have anything due on a the day under “Next update on” column in the excel file, without me opening the excel file.  If there is something due for update on the day, I would get a dialog box (picture above) to open the excel file, if not, the dialog box will not pop up.

Here is the script below, it’s very simple but it works.

Remark: I created an .exe file from .py using pyinstaller, and then I put a shortcut of the .exe file in the startup folder (Win+R —> shell:startup).

Alternatively, you can create a scheduled task in  Windows (in system tools) for auto-running the script at a specific hour.

===================================
#! python3 -- Created on Dec 7 2018
import openpyxl
import tkinter.messagebox
from datetime import date
import os

#Get the workbook, worksheet
file = "AR.xlsx"
wb = openpyxl.load_workbook(file)
ws = wb['Sheet1']

#Iterate through the rows of column "Next update on" = Column D = 4
for i in range(2, ws.max_row+1):
   next_update_datetime = str(ws.cell(row=i, column=4).value)
   next_update_date = next_update_datetime[0:10]
   if next_update_date == str(date.today()):
       result = tkinter.messagebox.askquestion("AR Progress Update Reminder", "You need to update AR today.  Would you like to open the workbook?", icon='question')
       if result == 'yes':
           os.startfile(file)
           break
       else:
           break
===================================

Comments

Popular posts from this blog

DIY Keyboard drawer installation

Completion Date: May 24, 2020 Work from home has given me chance to use my DIY table (35cm*50cm) ever more than before.  I feel great, but I realize the fact that I don’t have enough space if I want to work on my iPad at the same time.  I bought this mini drawer tracks so I can create this space. Material:  - 10 inch (25cm) keyboard drawer tracks, 1 pair (Taobao, RMB12.5) - 24*36cm wooden board (left over I have at home) Steps: 1.  Stretch the keyboard tracks to full extent.  Fit the wooden board to the end of the track and mark the holes with pencil. 2. This is 2.5mm drill bit.  Drill pilot holes to the marked holes.  Do the same for the other side. 3. Take my table top out and flip upside down.  Fit the keyboard drawer and trace the outline and mark the holes with pencil.  Re-verify the keyboard outer edge aligns in parallel with the table top’s outer edge. 4. Drill the holes and screws in to fix the keyboard drawer.  T

Gear investigation: Banbao Lego pirate ship on a swing

Completion date: May 14, 2020 1. Gear ratio is 16:24. The top spinning is at 0.66x of motor. I thought that the black gear connection just pass on same speed, but by experiment, the speed gears has the same effect just like when they are in contact. 2. By connecting the gears via the connection links, the gears turn in the same direction. 3. By connecting the gears via the connection links, it solves the distance problem between the two gears with a simple solution.  Without the connection links, many gears would be needed to get to the top. 4. I think this pirate ship is a tricky one, because one would have to tune the spinning speed to match the latency of the ship for the swinging motion to be smooth left-right-left-right. How to Give the push at the right time?  Also, the motor and the gears can get damaged when the motion is always interrupted.

Star cushion

Completion date: Jun 12 2020 Steps 1. Trace the star shape onto the fabric.  Double over the fabric.  Apply pins to secure the edges.  Cut out. 2. Install a platform on the sewing machine.  3. Whenever I need to turn the fabric I place the needle down on the fabric before turning the fabric.  Sew until I get a 15 cm opening. 4. Flip the fabric inside out and put the foam filling inside the star cushion.  Bind off the opening by hand sewing. My daughter requested for a star cushion.  I recycled filling of a foam-type cushion into this one.  This was the first time I used a platform.  The table was not long enough but I put something underneath to support the platform.  She was pleased with it though it wasn’t pink as she originally requested.  Below in the picture was her little hand!