Skip to content

Commit

Permalink
Add timestamped upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Javex committed Sep 26, 2023
1 parent aa2883f commit 7af45c2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/scrape-woolies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ jobs:
with:
role-to-assume: "${{ vars.TARGET_ROLE_ARN }}"
aws-region: ap-southeast-2
- run: aws s3 cp ./woolies_all.json s3://grocery-scrape-au/woolies_all.json
- run: aws s3 sync ./woolies/ s3://grocery-scrape-au/wooles/
15 changes: 13 additions & 2 deletions woolies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import requests
import json
import sys
import pathlib
from datetime import datetime


class WooliesAPI:
Expand Down Expand Up @@ -97,6 +99,16 @@ def save_cache(cache_data):
f.write(json.dumps(cache_data))


def save_data(categories):
now = datetime.now()
date_str = now.strftime("%Y-%m-%d")
fname = f"{date_str}.json"
save_dir = pathlib.Path(f"woolies")
save_dir.mkdir(exist_ok=True)
fpath = save_dir / fname
fpath.write_text(json.dumps(categories))


def main():
quick = False
if len(sys.argv) > 1 and sys.argv[1] == "--quick":
Expand Down Expand Up @@ -126,8 +138,7 @@ def main():
if quick:
break
#save_cache(categories)
with open('woolies_all.json', 'w') as f:
f.write(json.dumps(categories))
save_data(categories)
#print(json.dumps(category, indent=4))


Expand Down

0 comments on commit 7af45c2

Please sign in to comment.