Workflow-App/Workflow/scripts/_date_test.py

30 lines
1.3 KiB
Python
Raw Permalink Normal View History

import os, requests, pathlib
from datetime import datetime
for line in pathlib.Path(r'C:\Users\SJ\.minimax-agent\projects\Workflow\.env.local').read_text().splitlines():
if line.strip() and '=' in line and not line.startswith('#'):
k, v = line.split('=', 1)
os.environ.setdefault(k.strip(), v.strip())
token = os.environ['PB_TOKEN']
h = {'Authorization': f'Bearer {token}', 'Content-Type': 'application/json'}
dt = datetime.now()
formats = [
('PB space + .sssZ', dt.strftime('%Y-%m-%d %H:%M:%S.') + f'{dt.microsecond // 1000:03d}Z'),
('ISO T + .sssZ', dt.strftime('%Y-%m-%dT%H:%M:%S.') + f'{dt.microsecond // 1000:03d}Z'),
('date only', dt.strftime('%Y-%m-%d')),
('PB space no ms', dt.strftime('%Y-%m-%d %H:%M:%SZ')),
('ISO no ms', dt.isoformat()),
]
rec = 'zrduajho6xfpb3q' # WOEL row
for label, fmt in formats:
r = requests.patch(
f'https://pb.agent.apphub.co.za/api/collections/ysterbaard_SARS_EMP201_PAYE/records/{rec}',
headers=h, json={'last_updated': fmt}, timeout=15,
)
print(f'{label:25} status={r.status_code}', end='')
if r.status_code < 400:
d = r.json()
stored = d.get('last_updated')
print(f' stored={stored!r}')
else:
print(f' err={r.text[:200]}')