How to use canonical_json method in localstack

Best Python code snippet using localstack_python

process.py

Source:process.py Github

copy

Full Screen

1#!/usr/bin/env python32import argparse3import logging4import re5import shutil6from typing import List, Tuple, Optional 7from pathlib import Path8# Matches a filename with exactly one set of brackets (NUM) in it9copied_file_pattern = re.compile('[^()]*(\(\d+\))[^()]*')10video_formats = {'.mov', '.mp4'}11video_formats |= set(map(lambda x: x.upper(), video_formats))12image_formats = {'.jpeg', '.jpg', '.png', '.heic'}13image_formats |= set(map(lambda x: x.upper(), image_formats))14def all_media_files(dir: Path) -> List[Path]:15 assert dir.exists()16 res = []17 def recur(dir: Path) -> None:18 assert dir.is_dir()19 for child in dir.iterdir():20 if child.is_dir():21 recur(child)22 elif child.suffix == '.json' or child.name.startswith('.'):23 pass24 else:25 res.append(child)26 recur(dir)27 return res28def corresponding_json(media: Path) -> Optional[Path]:29 # the .json files appear to have a 51 char limit, and they just truncate the prefix30 possible_names = [31 media.name[:46],32 media.name.replace('-edited', '')[:46],33 ]34 match = copied_file_pattern.match(media.name)35 if match is not None:36 brackets = match.group(1)37 possible_names.append(38 media.name.replace(brackets, '')[:46] + brackets39 )40 # live photo's video component41 if media.suffix in video_formats:42 for image_format in image_formats:43 possible_names.append(44 (media.stem + image_format)[:46]45 )46 for name in possible_names:47 candidate = media.with_name(name + '.json')48 if candidate.exists():49 return candidate50 return None51def main():52 logging.basicConfig(level='INFO', format='[%(levelname)s] (%(asctime)s) : %(message)s')53 parser = argparse.ArgumentParser()54 parser.add_argument('google_photos_folder', type=str)55 args = parser.parse_args()56 folder = Path(args.google_photos_folder).resolve()57 media_files : List[Path] = all_media_files(folder)58 logging.info('%s', f'found %{len(media_files)} media files')59 media_and_json : List[Tuple[Path, Optional[Path]]] = list(map(lambda x: (x, corresponding_json(x)), media_files))60 for media, json in media_and_json:61 if not json:62 logging.warning('%s', f"Couldn't find corresponding JSON of {str(media)}")63 continue64 # just throw .json to the end of the media name, so the exiftool command will work65 canonical_json = media.with_name(media.name + '.json')66 if json.name != canonical_json.name:67 logging.debug('%s', f'copying {str(json)} -> {str(canonical_json)}')68 shutil.copyfile(json, canonical_json)69 # see https://legault.me/post/correctly-migrate-away-from-google-photos-to-icloud70 logging.info('%s', f'now you can run: exiftool -r -d %s -tagsfromfile "%d/%F.json" "-GPSAltitude<GeoDataAltitude" "-GPSLatitude<GeoDataLatitude" "-GPSLatitudeRef<GeoDataLatitude" "-GPSLongitude<GeoDataLongitude" "-GPSLongitudeRef<GeoDataLongitude" "-Keywords<Tags" "-Subject<Tags" "-Caption-Abstract<Description" "-ImageDescription<Description" "-DateTimeOriginal<PhotoTakenTimeTimestamp" -ext "*" -overwrite_original -progress --ext json "{folder}"')71if __name__ == '__main__':...

Full Screen

Full Screen

test_serializer.py

Source:test_serializer.py Github

copy

Full Screen

...4# Kinto specific5#6def test_supports_records_as_iterators():7 records = iter([{"bar": "baz", "last_modified": "45678", "id": "1"}])8 canonical_json(records, "45678")9def test_provides_records_in_data_along_last_modified():10 records = [{"bar": "baz", "last_modified": "45678", "id": "1"}]11 serialized = json.loads(canonical_json(records, "45678"))12 assert "data" in serialized13 assert "last_modified" in serialized14def test_orders_records_by_id():15 records = [16 {"bar": "baz", "last_modified": "45678", "id": "2"},17 {"foo": "bar", "last_modified": "12345", "id": "1"},18 ]19 serialized = json.loads(canonical_json(records, "45678"))20 assert serialized["last_modified"] == "45678"21 assert serialized["data"][0]["id"] == "1"22 assert serialized["data"][1]["id"] == "2"23def test_removes_deleted_items():24 record = {"bar": "baz", "last_modified": "45678", "id": "2"}25 deleted_record = {"deleted": True, "last_modified": "12345", "id": "1"}26 records = [deleted_record, record]27 serialized = canonical_json(records, "42")28 assert [record] == json.loads(serialized)["data"]29#30# Standard31#32def test_does_not_alter_records():33 records = [34 {"foo": "bar", "last_modified": "12345", "id": "1"},35 {"bar": "baz", "last_modified": "45678", "id": "2"},36 ]37 canonical_json(records, "45678")38 assert records == [39 {"foo": "bar", "last_modified": "12345", "id": "1"},40 {"bar": "baz", "last_modified": "45678", "id": "2"},41 ]42def test_preserves_data():43 records = [44 {"foo": "bar", "last_modified": "12345", "id": "1"},45 {"bar": "baz", "last_modified": "45678", "id": "2"},46 ]47 serialized = canonical_json(records, "45678")...

Full Screen

Full Screen

utils.py

Source:utils.py Github

copy

Full Screen

1import json2def record_size(record):3 # We cannot use rapidjson here, since the `separator` option is not available.4 canonical_json = json.dumps(record, sort_keys=True, separators=(",", ":"))...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful