-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda_function.py
36 lines (26 loc) · 1.12 KB
/
lambda_function.py
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
import json
import requests
import base64
from bs4 import BeautifulSoup, Tag
from env import DISCORD_WEBHOOK_URL, DISCORD_ROLE_ID
def lambda_handler(event, context):
return_obj = {
"statusCode": 200,
"body": json.dumps({ "executed": False, "rqid": context.aws_request_id })
}
soup = BeautifulSoup(event["body"])
entry = soup.entry
if not entry:
return_obj["body"] = json.dumps({ "executed": False, "rqid": context.aws_request_id, "error": "No entry found" })
return return_obj
title = entry.title
link = entry.find("link", rel="alternate")
channel = entry.author.id
return_obj["body"] = json.dumps({ "executed": False, "rqid": context.aws_request_id, "title": title.string })
mention_str = ('@....everyone, ' if DISCORD_ROLE_ID == 'everyone' else '<@&' + DISCORD_ROLE_ID + '>, ')
data = {
"content": "Hey " + mention_str + "**" + channel.string + "** just uploaded a video! Check out '" + title.string + "' here:\n" + link.get("href")
}
result = requests.post(DISCORD_WEBHOOK_URL, json = data)
result.raise_for_status()
return return_obj