Skip to content

Commit

Permalink
Merge pull request #10 from TanmoySG/update-app
Browse files Browse the repository at this point in the history
Update Check for existing data
  • Loading branch information
TanmoySG authored Sep 15, 2024
2 parents 472126d + bd986de commit 7b4fc4c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions push/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def create(base_url, database_name, collection_name, payload) -> str:
)

response_json = json.loads(response.text)
collection_records = response_json["response"]["records"]
collection_records: dict = response_json["response"]["records"]
primary_key_field = response_json["response"]["primaryKey"]

for record in RECORDS_ARRAY:
Expand All @@ -103,23 +103,27 @@ def create(base_url, database_name, collection_name, payload) -> str:
field_value: str = record[primary_key_field]

if record[primary_key_field] not in collection_records:
action = "create"
res = create(
BASE_URL,
DATABASE_NAME,
COLLECTION_NAME,
record,
)
action = "create"
else:
res = patch(
BASE_URL,
DATABASE_NAME,
COLLECTION_NAME,
record,
primary_key_field,
record[primary_key_field],
)
action = "patch"
# if database record and repo record are same, skip patch
if record == collection_records.get(record[primary_key_field])["data"]:
res = "no change in data, skipping patch"
else:
res = patch(
BASE_URL,
DATABASE_NAME,
COLLECTION_NAME,
record,
primary_key_field,
record[primary_key_field],
)

# log the response
extra_fields = {
Expand Down

0 comments on commit 7b4fc4c

Please sign in to comment.