Skip to content

Commit cf37b5a

Browse files
authored
Merge pull request #60 from stefanv/check-expiry
Check expiry date when processing jobs
2 parents 0eef2b2 + 6db1a1b commit cf37b5a

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tools/bundle_posts.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@ def default(self, obj):
3030
sys.exit(1)
3131

3232
post = yaml.load(open(job, "r"), Loader=yaml.Loader)
33+
34+
expires = post.get('expires')
35+
if not expires:
36+
print(f'\nError: Missing "expires" field in {job}.')
37+
sys.exit(1)
38+
39+
if not isinstance(expires, datetime.date):
40+
# Try to parse expiry date, in case YAML loader didn't do so already
41+
try:
42+
expires = datetime.date.fromisoformat(str(expires))
43+
except ValueError:
44+
print(f'\nError: Invalid "expires" date format in {job}: {expires}. Use YYYY-MM-DD.')
45+
sys.exit(1)
46+
47+
# Normalize datetime to date (no time) to avoid timestamp issues in JS
48+
if isinstance(expires, datetime.datetime):
49+
print(f'\nStripping timestamp from expiry date in {job}: {expires}')
50+
expires = expires.date()
51+
52+
post['expires'] = expires
3353
post['date'] = date
3454
post['id'] = os.path.splitext(os.path.basename(job))[0]
3555

0 commit comments

Comments
 (0)