-
Notifications
You must be signed in to change notification settings - Fork 0
/
webhook.py
42 lines (35 loc) · 1.51 KB
/
webhook.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
37
38
39
40
41
42
from datetime import datetime
import json
import requests as rq
def send(group,webhook,site,title,url,thumbnail,fields,logger):
"""
Sends a Discord webhook notification to the specified webhook URL
"""
fields.append({
"name": "Links",
"value": f"[StockX](https://stockx.com/search?s={title.replace(' ','+')}) | [GOAT](https://www.goat.com/search?query={title.replace(' ','+')}) | [Wethenew](https://wethenew.com/search?type=product&q={title.replace(' ','+')})",
"inline": False
})
data = {
"username": group["Name"],
"avatar_url": group["Avatar_Url"],
"embeds": [{
"title": title,
"url": url,
"thumbnail": {"url": thumbnail},
"fields": fields,
"color": group['Colour'],
"footer": {
"text": f"{group['Name']} | {datetime.now().strftime('%d.%m.%Y %H:%M:%S')}",
"icon_url": group["Avatar_Url"]
},
"author": {
"name": site
}
}
]
}
result = rq.post(webhook, data=json.dumps(data), headers={"Content-Type": "application/json"})
result.raise_for_status()
logger.info(msg=f'[{site}] Successfully sent Discord notification to {group["Name"]} with product {title}')
print(f'[{site}] Successfully sent Discord notification to {group["Name"]} with product {title}')