-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview_mods.py
124 lines (103 loc) · 4.01 KB
/
review_mods.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import os
import os.path
from bs4 import BeautifulSoup
from urllib import request
import re
import shutil
import sys
import logging
import sys
import traceback
import json
from datetime import datetime
from urllib import request
from discord_webhook import DiscordWebhook, DiscordEmbed
from pathlib import Path
import a2s
from process_html import loadMods
from dotenv import dotenv_values
import requests
from pathlib import Path
import argparse
import asyncio
import aiohttp
import pandas
import csv
#######################################################
config = dotenv_values(".env")
PATH_BASE = config["PATH_BASE"]
PATH_STAGING = config["PATH_STAGING"]
PATH_STAGING_MODS = config["PATH_STAGING_MODS"]
PATH_PRESETS = config["PATH_PRESETS"]
PATH_SERVER = config["PATH_SERVER"]
STEAM_LOGIN = config["STEAM_LOGIN"]
STEAM_PASSWORD = config["STEAM_PASSWORD"]
PANEL_SERVERS = config["PANEL_SERVERS"]
PANEL_IP = config["PANEL_IP"]
PANEL_LOGIN = config["PANEL_LOGIN"]
PANEL_PASSWORD = config["PANEL_PASSWORD"]
DISCORD_WEBHOOK = config["DISCORD_WEBHOOK"]
def get_workshop_link(mod_id):
return f"https://steamcommunity.com/sharedfiles/filedetails/?id={mod_id}"
#return f"https://steamcommunity.com/sharedfiles/filedetails/changelog/{mod_id}"
def get_workshop_size(mod_id):
PATTERN = re.compile(r"detailsStatsContainerRight.*?<div .*?\>(.*?)</div>", re.DOTALL)
CLEANHTML = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});')
response = request.urlopen(get_workshop_link(mod_id)).read()
response = response.decode("utf-8")
match = PATTERN.search(response)
if match:
string_size = re.sub(CLEANHTML, '', match.group(1).replace("<br>", "\n").replace("</b>", "\n"))
clean_number = float(string_size[:-3])
if "KB" in string_size:
return round(clean_number / 1000000,5)
elif "MB" in string_size:
return round(clean_number / 1000,5)
elif "GB" in string_size:
return round(clean_number / 1,5)
else:
return 0
else:
return ""
def get_workshop_required_item_ids(mod_id):
response = request.urlopen(get_workshop_link(mod_id)).read()
soup = BeautifulSoup(response, 'html.parser')
# Find the container with the required items
required_items_container = soup.find('div', class_='requiredItemsContainer')
if required_items_container:
# Extract all links with IDs in the required items container
links = required_items_container.find_all('a', href=True)
ids = []
for link in links:
match = re.search(r'id=(\d+)', link['href'])
if match:
ids.append(match.group(1))
print(ids)
return ids
#######################################################
if __name__ == "__main__":
presets = []
core_mods = get_workshop_required_item_ids("3038124203")
map_mods = get_workshop_required_item_ids("3038082542")
am2_mods = get_workshop_required_item_ids("3397107962")
for preset in os.listdir(PATH_PRESETS):
mods = []
if preset.endswith(".html"):
preset_mods = loadMods(os.path.join(PATH_PRESETS, preset))
for preset_mod in preset_mods:
print(preset_mod)
preset_pack = "Unknown"
if preset_mod["ID"] in core_mods:
preset_pack = "Core"
elif preset_mod["ID"] in map_mods:
preset_pack = "Maps"
elif preset_mod["ID"] in am2_mods:
preset_pack = "AM2 Main"
mod = {"NAME": preset_mod["name"], "ID": preset_mod["ID"], "LINK": get_workshop_link(preset_mod["ID"]), "SIZE": get_workshop_size(preset_mod["ID"]), "PRESET": preset_pack}
print(mod)
mods.append(mod)
keys = mods[0].keys()
with open(f'preview/{preset[:-5]}.csv', 'w', newline='') as output_file:
dict_writer = csv.DictWriter(output_file, keys)
dict_writer.writeheader()
dict_writer.writerows(mods)