-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathannounce_ports.py
89 lines (74 loc) · 2.76 KB
/
announce_ports.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import requests
import json
from random import choice
import os
webhook_url = os.environ["NEWS_WEBHOOK_URL"]
screenshot_url_main = (
"https://raw.githubusercontent.com/PortsMaster/PortMaster-New/main/ports/"
)
screenshot_url_multiverse = (
"https://raw.githubusercontent.com/PortsMaster-MV/PortMaster-MV-New/main/ports/"
)
emojis = ["🎉","🍾","🎊","🎇","🥂","🎈","🥳","🎆","🧨","🤯","💥","🔥"]
def post_message(post_title, port_title, link, image,comment):
# https://gist.github.com/Birdie0/78ee79402a4301b1faf412ab5f1cdcf9
data = {
"username": "Announcement Bot",
"content": post_title,
"embeds": [
{
"title": f"{port_title}",
"url": f"{link}",
"description": f"{comment}",
"image": {"url": f"{image}"},
}
],
}
response = requests.post(webhook_url, json=data)
newPorts = []
response = requests.get("https://raw.githubusercontent.com/PortsMaster/PortMaster-Info/main/ports.json")
portJson = response.json()
for port in portJson["ports"]:
newPorts.append(port)
oldPorts = []
try:
with open("ports.json") as portsjson:
parsed_json = json.load(portsjson)
for port in parsed_json:
oldPorts.append(port)
except Exception as e:
pass
if len(oldPorts) < 1:
oldPorts = newPorts
with open("ports.json", "w", encoding="utf8") as outfile:
for port in portJson["ports"]:
if port not in oldPorts:
title = portJson["ports"][port]["attr"]["title"]
description = portJson["ports"][port]["attr"]["desc"]
porter = ",".join(portJson["ports"][port]["attr"]["porter"])
imgurl = (
screenshot_url_main
+ port.replace(".zip", "/")
+ portJson["ports"][port]["attr"]["image"]["screenshot"]
)
if portJson["ports"][port]["source"]["repo"] == "multiverse":
imgurl = (
screenshot_url_multiverse
+ port.replace(".zip", "/")
+ portJson["ports"][port]["attr"]["image"]["screenshot"]
)
link = "https://portmaster.games/detail.html?name=" + port.replace(
".zip", ""
)
thanks = f"\n\n Thanks to {porter} for bringing this game to PortMaster"
comment = description + thanks
oldPorts.append(port)
post_message(
post_title=f"{choice(emojis)} {title} is now on PortMaster! {choice(emojis)}",
port_title=title,
link=link,
image=imgurl,
comment=comment
)
break
outfile.write(json.dumps(oldPorts, indent=2, sort_keys=True))