Python Forum
[PyGUI] From comand line to GUI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGUI] From comand line to GUI
#2
An improvement for your date-finder.

def get_next_date(visit_dates, visit_after, next_visit=10):
    # this could convert visit_dates and visit_after from
    # iso8601 timestamp (str) to date objects
    # visit_dates = [datetime.date.fromisoformat(d) for d in visit_dates]
    # visit_after = datetime.date.fromisoformat(visit_after)
    try:
        # Exception 1: Item not in visit_dates -> ValueError
        #              The date was not in the list
        # Exception 2: Index > than length of list -> IndexError
        #              In this case, it comes from + 1
        #              Date was found, but no date after
        return visit_dates[visit_dates.index(visit_after) + next_visit]
        # If no Exception happens, it will return the result
    except (ValueError, IndexError):
        # Catching this two Exceptions
        pass
    # raise an ValueError instead of returning None or something else
    # Catch the ValueError Exception on the caller side.
    raise ValueError(f'No visit date after {visit_after}')
If you handle with workdays, repeating dates etc. you should look for dateutil
A tool to handle timezones: pendulum
Previous I used pytz, but I got the tip from here that pendulum is easier to use.

I did not look for the GUI-Code, but with a function you can handle it more dynamic.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
From comand line to GUI - by elmatte - Dec-23-2019, 09:18 AM
RE: From comand line to GUI - by DeaD_EyE - Dec-23-2019, 10:01 AM
RE: From comand line to GUI - by Denni - Dec-23-2019, 03:32 PM
RE: From comand line to GUI - by elmatte - Dec-24-2019, 11:32 AM
RE: From comand line to GUI - by elmatte - Dec-24-2019, 07:12 PM
RE: From comand line to GUI - by Denni - Dec-26-2019, 03:20 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020