-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
42 lines (31 loc) · 1.32 KB
/
lambda_function.py
File metadata and controls
42 lines (31 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import urllib.request
BASE_URL = "https://fforacle-gegydpfvezf5axc5.centralus-01.azurewebsites.net/api"
def call_put(path):
url = f"{BASE_URL}{path}"
req = urllib.request.Request(url, method="PUT")
with urllib.request.urlopen(req) as res:
return res.status
def call_post(path):
url = f"{BASE_URL}{path}"
req = urllib.request.Request(url, method="POST")
with urllib.request.urlopen(req) as res:
return res.status
def lambda_handler(event, context):
task = event.get("task")
try:
if task == "weekly":
status = call_put("/AutoUpdate/weekly")
return {"statusCode": status, "body": "Weekly update OK"}
elif task == "daily":
status = call_put("/AutoUpdate/daily")
return {"statusCode": status, "body": "Daily update OK"}
elif task == "increment":
status = call_put("/AppState/increment")
return {"statusCode": status, "body": "AppState increment OK"}
elif task == "email-articles":
status = call_post("/Espn/emailArticles")
return {"statusCode": status, "body": "Email article sending OK"}
else:
return {"statusCode": 400, "body": f"Unknown task: {task}"}
except Exception as e:
return {"statusCode": 500, "body": str(e)}