[server]: Add return_luas_data
This commit is contained in:
21
server/src/functions/return_luas_data/lambda_function.py
Normal file
21
server/src/functions/return_luas_data/lambda_function.py
Normal file
@ -0,0 +1,21 @@
|
||||
import xmltodict
|
||||
import json
|
||||
import os
|
||||
import requests
|
||||
|
||||
def lambda_handler(event, context):
|
||||
try:
|
||||
luas_stop_code = event['queryStringParameters']['luasStopCode']
|
||||
response = requests.get(f"http://luasforecasts.rpa.ie/xml/get.ashx?action=forecast&stop={luas_stop_code}&encrypt=false")
|
||||
xml_dict = xmltodict.parse(response.text)
|
||||
|
||||
return {
|
||||
'statusCode': 200,
|
||||
'body': json.dumps(xml_dict)
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
return {
|
||||
'statusCode': 500,
|
||||
'body': json.dumps({'error': str(e)})
|
||||
}
|
Reference in New Issue
Block a user