-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-items-webhook.py
53 lines (44 loc) · 1.38 KB
/
new-items-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
43
44
45
46
47
48
49
50
51
52
53
# SPDX-License-Identifier: WTFPL
import json
from pathlib import Path
from sanitize_filename import sanitize
import subprocess
import sys
import os.path
import time
import csv
from git import Repo
import requests
import os
links = []
repo = Repo(".")
for item in repo.index.diff("HEAD"):
if item.a_path.startswith("gamebanana-items"):
with open(item.a_path, "r", encoding="utf-8") as f:
j = json.load(f)
for file in j["_aFiles"]:
links.append([file["_sDownloadUrl"], sanitize(str(file["_idRow"]) + "_" + file["_sFile"]), j["_sName"], file["_nFilesize"], j["_idRow"]])
alreadydone = os.listdir("../gamebanana-scrape")
death = True
for x in links:
filename = "../gamebanana-scrape/" + str(x[4]) + "_" + x[1]
if (str(x[4]) + "_" + x[1]) in alreadydone:
continue
death = False
print("\nfound {filename}")
open(filename, "w").close()
data = {
"content": "new download at https://gamebanana.com/mods/"+str(x[4])+" "+x[2],
"username": "gamebanana peeper",
"embeds": [],
}
result = requests.post(os.environ.get("WEBHOOK_URL"), json=data)
try:
result.raise_for_status()
except requests.exceptions.HTTPError as err:
print(err)
else:
print("Payload delivered successfully, code {}.".format(result.status_code))
time.sleep(0.333)
if death:
sys.exit(1)