Skip to content

Commit

Permalink
Update ToEnWikipediaBot.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jnton authored Apr 15, 2024
1 parent 1a020fe commit a2821a6
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions ToEnWikipediaBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,19 @@ async def async_lambda_handler(event, context):
return {'statusCode': 400, 'body': json.dumps({'message': 'No update payload'})}

def lambda_handler(event, context):
print("Raw event:", event)
print("Body parsed:", body)
print("Received event:", event) # Log the incoming event data
try:
body = json.loads(event['body']) # Parse the JSON body
# Now, you can access the body as a Python dictionary
print("Received update:", body)
except json.JSONDecodeError as error:
print("Error decoding JSON:", error)
return {
"statusCode": 400,
"body": json.dumps({"message": "Invalid JSON received"})
}
"""Synchronous wrapper for the asynchronous Lambda handler."""
# Check if 'body' exists in the event
if 'body' not in event:
Expand All @@ -242,6 +254,10 @@ def lambda_handler(event, context):
except json.JSONDecodeError as e:
logger.error(f"Error decoding event body: {str(e)}")
return {'statusCode': 400, 'body': json.dumps({'message': 'JSON decode error'}), 'headers': {'Content-Type': 'application/json'}}
return {
"statusCode": 200,
"body": json.dumps({"message": "Success"})
}

# Run the asynchronous handler and pass the parsed JSON
return asyncio.run(async_lambda_handler(event_body, context))
Expand Down

0 comments on commit a2821a6

Please sign in to comment.