My goal for this go round is to figure out the age of a Raspberry PI file through Python and figure out if it's old enough to delete based on the current date and whatever parameter defines a file as being too old.
To do this, we're going to need the Python TIME module again.
I'm thinking that I can use one of the time functions to subtract my age parameter from the current date and create a variable consisting of my "expiration" date. Any critter pic with a creation date older than this date should be deleted.
I actually need the datetime module to perform the math with the dates. It doesn't appear that the TIME module allows for math with time components?
So, I have to collect the current date as a variable:
current_date = datetime.date.today()
And a variable (or, specifically a duration to the datetime module) representing the amount of time to take away to create an expiration date:
y = datetime.timedelta(weeks = 2)
The datetime module allows you to subtract a duration object from a date object. The expiration date will be as follows:
exp_date = current_date - y
As usual, I didn't get as far as I had hoped. Next time, we'll work on getting the file dates from the critter pics and doing the compare.
No comments:
Post a Comment