Jul-01-2023, 11:06 PM
This is a great conversation, I read tons of docs and started understanding (kind of) some of the "date times" I'm working with. I think for now I should just stick with the snippet shared by the All Great and all Powerful deanhystad
both "times" are in UTC and localized for the Pacific NW.
if it is true that all timestamps are UTC then the following should filter the files I'm looking for:
What did I do wrong?
By the way, I was thinking maybe the line below is not localized it is a UTC timestamp but not tied up to any time zone.
TypeError: 'float' object is not callable
Again, I really appreciate you guys looking into it!
Thank you!

from datetime import datetime, date, time, timedelta from pytz import timezone from pathlib import Path # Get start and end of day in Seattle start_time = datetime.combine(date.today(), time(), tzinfo=timezone("US/Pacific")) end_time = start_time + timedelta(hours=24) print(start_time, end_time) # Convert to timestamps. start_time = start_time.timestamp() end_time = end_time.timestamp() print(start_time, end_time) # Print all files that were modified today. folder = Path(__file__).parent # Scan folder that contains this file. for file in folder.iterdir(): mtime = file.stat().st_mtime if start_time <= mtime < end_time: print(file.name, mtime, datetime.fromtimestamp(mtime))I understand that the range of "datetimes" for the files to download from Asia is set by the "start_time" and "end_time"
both "times" are in UTC and localized for the Pacific NW.
if it is true that all timestamps are UTC then the following should filter the files I'm looking for:
for file in folder.iterdir(): mtime = file.stat().st_mtime if start_time <= mtime < end_time:but it seems I'm getting the "wrong timestamps". Then I thought OK, let's localize my "start_time" and "end_time" for the Kuala_Lumpur because it is local time for the hosts I'm trying to get the files from.
#start_time = datetime.combine(date.today(), time(), tzinfo=timezone("US/Pacific")) start_time = datetime.combine(date.today(), time(), tzinfo=timezone("Asia/Kuala_Lumpur")) end_time = start_time + timedelta(hours=24) print(start_time, end_time) # Convert to timestamps. start_time = start_time.timestamp() end_time = end_time.timestamp() print(start_time, end_time)It seems I'm still getting the files with "wrong" timestamps. I know that the files have the wrong timestamps because when I open them data inside is from tomorrow...
What did I do wrong?
By the way, I was thinking maybe the line below is not localized it is a UTC timestamp but not tied up to any time zone.
mtime = file.stat().st_mtimeI tried :
mtime3 = ef.stat().st_mtime(pytz.utc)But it produces an error:
TypeError: 'float' object is not callable
Again, I really appreciate you guys looking into it!
Thank you!