Python Forum
Downloading time zone aware files, getting wrong files(by date))s
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Downloading time zone aware files, getting wrong files(by date))s
#7
If you can't install pendulum you could fall back to constructing a start of day timestamp.
from datetime import datetime, date, time, timedelta
from zoneinfo import ZoneInfo
from pathlib import Path
 
items = '/somehost/c$/directory/'  # <--- Some Host in Asia/Kuala_Lumpur 
ndir_p = 'D:somedir/'     # <--------------- Directory for files from Kuala_Lumpur

# Get timestamps for start of today and start of yesterday.
# Use tzinfo=ZoneInfo('Asia/Kuala_Lumpur') to get these for Kuala Lumpur.
today = datetime.combine(date.today(), time(), tzinfo=ZoneInfo("America/Vancouver"))
yesterday = (today - timedelta(hours=24)).timestamp()
today = today.timestamp()
for echf in Path(items).iterdir():
    if echf.is_file():                           
        if yesterday <= echf.stat().st_mtime < today:  # There will be zero gap and zero overlap if you run this once every day.
            try:
                shutil.copy2(echf, ndir_p)                           
            except OSError as st :
                print(f" -- {st}")
tester_V likes this post
Reply


Messages In This Thread
RE: Downloading time zone aware files, getting wrong files(by date))s - by deanhystad - Jul-22-2023, 11:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Invalid Date Format fo Cached Files jland47 1 212 May-22-2024, 07:04 PM
Last Post: deanhystad
  Trying to generating multiple json files using python script dzgn989 4 325 May-10-2024, 03:09 PM
Last Post: deanhystad
  Filer and sort files by modification time in a directory tester_V 5 500 May-02-2024, 05:39 PM
Last Post: tester_V
  [SOLVED] Loop through directories and files one level down? Winfried 3 402 Apr-28-2024, 02:31 PM
Last Post: Gribouillis
  Loop through all files in a directory? Winfried 10 765 Apr-23-2024, 07:38 PM
Last Post: FortuneCoins
Question Right way to open files with different encodings? Winfried 2 403 Apr-23-2024, 05:50 PM
Last Post: snippsat
  Open files in an existing window instead of new Kostov 2 449 Apr-13-2024, 07:22 AM
Last Post: Kostov
  Using zipfile module - finding folders not files darter1010 2 431 Apr-06-2024, 07:22 AM
Last Post: Pedroski55
  Compare current date on calendar with date format file name Fioravanti 1 369 Mar-26-2024, 08:23 AM
Last Post: Pedroski55
  Is it possible to extract 1 or 2 bits of data from MS project files? cubangt 8 1,243 Feb-16-2024, 12:02 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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