Ben ๐Ÿ‡ช๐Ÿ‡บ is a user on octodon.social. You can follow them or interact with them if you have an account anywhere in the fediverse. If you don't, you can sign up here.

Do any of you have experience with Python's datetime library?

I'm trying to track down a bug that may be related to parsing and the weird way that datetimes are formatted.

@LogicalDash I'm downloading an endless stream of jpegs from a public repository, and I want to throw out any files that are more than 24 hours old.

So if(str(datetime.today() - file_mod_time).find("1 day") != -1): <remove file>

This is definitely keeping my file range to the last 24 ish hours, but for some reason it also seems to be throwing out all of my data from around midnight +- 1 hour.

@Miredly What's file_mod_time? Is it the st_mtime field from the result of os.stat()?

@Miredly I can't get that snippet to work at the moment but wouldn't it be better to convert the file_mod_time to a datetime and just see if the difference is greater than 86400? I think you can use datetime.fromtimestamp for that.

Also I'd probably use datetime.now() rather than today if you want it to be 24 hours.

@benofbrown I was actually doing that already,

file_mod_time = datetime.fromtimestamp(os.stat(file).st_mtime)

Sorry for the confusion. datetime.now() vs. today() may actually be the solution to my problem. That seems like the kind of thing that would result in weirdness at midnight.

Ben ๐Ÿ‡ช๐Ÿ‡บ @benofbrown

@Miredly You're welcome! Hope it works!

ยท Web ยท 0 ยท 0