Skip to content

Commit

Permalink
Merge pull request #103 from SpaceCowMedia/camelize-json
Browse files Browse the repository at this point in the history
* Camelizing json with pyhumps
* Adding s3 upload for import_combos
  • Loading branch information
accassid authored Jun 2, 2023
2 parents 28d4fe7 + c79db08 commit ee53c27
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/.kubernetes/jobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
command:
- /bin/sh
- -c
- python manage.py update_cards; python manage.py import_combos; python manage.py export_variants --s3;
- python manage.py update_cards; python manage.py import_combos --s3; python manage.py export_variants --s3;
env:
- name: SECRET_KEY
valueFrom:
Expand Down
1 change: 1 addition & 0 deletions backend/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Django==4.2.1
django-filter==23.2
django-sortedm2m==3.1.1
djangorestframework==3.14.0
pyhumps==3.8.0
8 changes: 5 additions & 3 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --resolver=backtracking
Expand Down Expand Up @@ -27,6 +27,8 @@ jmespath==1.0.1
# via
# boto3
# botocore
pyhumps==3.8.0
# via -r requirements.in
python-dateutil==2.8.2
# via botocore
pytz==2023.3
Expand All @@ -37,7 +39,7 @@ six==1.16.0
# via python-dateutil
sqlparse==0.4.4
# via django
tzdata==2023.3
# via django
typing-extensions==4.6.3
# via asgiref
urllib3==1.26.16
# via botocore
4 changes: 3 additions & 1 deletion backend/spellbook/management/commands/export_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from spellbook.models import Variant, Job
from spellbook.serializers import VariantSerializer
from ..s3_upload import upload_json_to_aws

import humps

DEFAULT_VARIANTS_FILE_NAME = 'variants.json'

Expand Down Expand Up @@ -58,6 +58,8 @@ def handle(self, *args, **options):
'variants': [prepare_variant(v) for v in variants_source],
}

result = humps.camelize(result)

if options['s3']:
self.stdout.write('Uploading to S3...')
upload_json_to_aws(result, DEFAULT_VARIANTS_FILE_NAME)
Expand Down
13 changes: 13 additions & 0 deletions backend/spellbook/management/commands/import_combos.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from spellbook.models import Feature, Card, Job, Combo, CardInCombo, Variant, IngredientInCombination
from spellbook.models.validators import MANA_SYMBOL
from ..scryfall import scryfall, update_cards
from spellbook.management.s3_upload import upload_json_to_aws


@dataclass(frozen=True)
Expand Down Expand Up @@ -174,6 +175,13 @@ def format_feature_name(feature: str) -> str:
class Command(BaseCommand):
help = 'Tries to import combos from the google sheet'

def add_arguments(self, parser):
parser.add_argument(
'--s3',
action='store_true',
dest='s3',
)

def log_job(self, job, message, style=lambda x: x):
self.stdout.write(style(message))
job.message += message + '\n'
Expand Down Expand Up @@ -354,6 +362,11 @@ def handle(self, *args, **options):
json.dump(variant_id_map, f)
json.dump(variant_id_map, fz)
self.log_job(job, 'Saving variant id map...done')

if options['s3']:
upload_json_to_aws(variant_id_map, 'variant_id_map.json')
self.log_job(job, 'Uploading variant map...done')

self.log_job(job, 'Generating variants...')
added, restored, deleted = generate_variants(job)
self.log_job(job, f'Generating variants...done. Added {added} variants, restored {restored} variants, deleted {deleted} variants.')
Expand Down

0 comments on commit ee53c27

Please sign in to comment.